ASTReader.h revision 4c30bb148b53c8063e940ca3e049ba4d270dc9d5
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"
19668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor#include "clang/Sema/ExternalSemaSource.h"
20c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl#include "clang/AST/DeclarationName.h"
21f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor#include "clang/AST/DeclObjC.h"
22833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall#include "clang/AST/TemplateBase.h"
2388a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor#include "clang/Lex/ExternalPreprocessorSource.h"
24cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor#include "clang/Lex/HeaderSearch.h"
256a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor#include "clang/Lex/PreprocessingRecord.h"
260a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor#include "clang/Basic/Diagnostic.h"
27668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor#include "clang/Basic/IdentifierTable.h"
287f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor#include "clang/Basic/SourceManager.h"
2917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor#include "llvm/ADT/APFloat.h"
300a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor#include "llvm/ADT/APInt.h"
310a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor#include "llvm/ADT/APSInt.h"
322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/ADT/OwningPtr.h"
332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/ADT/SmallVector.h"
34dc3c0d20375bda7775b2fade05b20e315798b9feDaniel Dunbar#include "llvm/ADT/StringRef.h"
352cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/Bitcode/BitstreamReader.h"
3603013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer#include "llvm/Support/DataTypes.h"
37d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor#include <deque>
38025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor#include <map>
392cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <string>
402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <utility>
412cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <vector>
422cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace llvm {
442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  class MemoryBuffer;
452cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
472cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace clang {
482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
497d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregorclass AddrLabelExpr;
500af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregorclass ASTConsumer;
512cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass ASTContext;
5295f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregorclass ASTIdentifierIterator;
53f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregorclass ASTUnit; // FIXME: Layering violation and egregious hack.
5468a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregorclass Attr;
552cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass Decl;
562cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass DeclContext;
576ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattnerclass NestedNameSpecifier;
586ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattnerclass CXXBaseSpecifier;
59ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Huntclass CXXConstructorDecl;
60cbb67480094b3bcb5b715acd827cbad55e2a204cSean Huntclass CXXCtorInitializer;
611de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregorclass GotoStmt;
626a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregorclass MacroDefinition;
63668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregorclass NamedDecl;
6456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr;
6514f79002e58556798e86168c63e48d533287eda5Douglas Gregorclass Preprocessor;
66668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregorclass Sema;
67025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorclass SwitchCase;
68c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redlclass ASTDeserializationListener;
69f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregorclass ASTWriter;
70c43b54cbc10654ed59de797898042e1a05265246Sebastian Redlclass ASTReader;
71d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redlclass ASTDeclReader;
72c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redlclass ASTStmtReader;
73c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redlclass ASTIdentifierLookupTrait;
74c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redlclass TypeLocReader;
75eb19485625c7529ffa644e10829533157a8e8d4fDaniel Dunbarstruct HeaderFileInfo;
760a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregorclass VersionTuple;
7711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis
787e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redlstruct PCHPredefinesBlock {
797e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// \brief The file ID for this predefines buffer in a PCH file.
807e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  FileID BufferID;
817e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl
827e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// \brief This predefines buffer in a PCH file.
83686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef Data;
847e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl};
85686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<PCHPredefinesBlock, 2> PCHPredefinesBlocks;
867e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl
87c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// \brief Abstract interface for callback invocations by the ASTReader.
8811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis///
89c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// While reading an AST file, the ASTReader will call the methods of the
9011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis/// listener to pass on specific information. Some of the listener methods can
91c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// return true to indicate to the ASTReader that the information (and
92571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl/// consequently the AST file) is invalid.
93571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redlclass ASTReaderListener {
9411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidispublic:
95571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  virtual ~ASTReaderListener();
961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives the language options.
9811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
9911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \returns true to indicate the options are invalid or false otherwise.
10011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual bool ReadLanguageOptions(const LangOptions &LangOpts) {
10111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
10211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
1031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives the target triple.
10511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
10611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \returns true to indicate the target triple is invalid or false otherwise.
107686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  virtual bool ReadTargetTriple(StringRef Triple) {
10811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
10911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
1101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives the contents of the predefines buffer.
11211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
11330c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl  /// \param Buffers Information about the predefines buffers.
11411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
1153c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param OriginalFileName The original file name for the AST file, which
1163c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// will appear as an entry in the predefines buffer.
1177b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar  ///
11811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \param SuggestedPredefines If necessary, additional definitions are added
11911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// here.
12011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
12111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \returns true to indicate the predefines are invalid or false otherwise.
1227e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
123686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                    StringRef OriginalFileName,
124277a6e752512cff286190d35cb353ce717e86b18Nick Lewycky                                    std::string &SuggestedPredefines,
125277a6e752512cff286190d35cb353ce717e86b18Nick Lewycky                                    FileManager &FileMgr) {
12611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
12711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
1281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives a HeaderFileInfo entry.
13012fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor  virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID) {}
1311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives __COUNTER__ value.
13311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual void ReadCounter(unsigned Value) {}
13411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis};
13511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis
136571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl/// \brief ASTReaderListener implementation to validate the information of
13711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis/// the PCH file against an initialized Preprocessor.
138571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redlclass PCHValidator : public ASTReaderListener {
13911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  Preprocessor &PP;
140c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader &Reader;
1411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  unsigned NumHeaderInfos;
1431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidispublic:
145c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  PCHValidator(Preprocessor &PP, ASTReader &Reader)
14611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    : PP(PP), Reader(Reader), NumHeaderInfos(0) {}
1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual bool ReadLanguageOptions(const LangOptions &LangOpts);
149686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  virtual bool ReadTargetTriple(StringRef Triple);
1507e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
151686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                    StringRef OriginalFileName,
152277a6e752512cff286190d35cb353ce717e86b18Nick Lewycky                                    std::string &SuggestedPredefines,
153277a6e752512cff286190d35cb353ce717e86b18Nick Lewycky                                    FileManager &FileMgr);
15412fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor  virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID);
15511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual void ReadCounter(unsigned Value);
156d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek
157d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenekprivate:
158d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  void Error(const char *Msg);
15911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis};
1602cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
161c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// \brief Reads an AST files chain containing the contents of a translation
162c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// unit.
1632cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor///
164c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// The ASTReader class reads bitstreams (produced by the ASTWriter
1652cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// class) containing the serialized representation of a given
1662cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// abstract syntax tree and its supporting data structures. An
167c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// instance of the ASTReader can be attached to an ASTContext object,
168c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// which will provide access to the contents of the AST files.
1692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor///
170c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// The AST reader provides lazy de-serialization of declarations, as
1712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// required when traversing the AST. Only those AST nodes that are
1722cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// actually required will be de-serialized.
173c43b54cbc10654ed59de797898042e1a05265246Sebastian Redlclass ASTReader
17488a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  : public ExternalPreprocessorSource,
1756a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor    public ExternalPreprocessingRecordSource,
176cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    public ExternalHeaderFileInfoSource,
17788a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor    public ExternalSemaSource,
1788c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor    public IdentifierInfoLookup,
1797f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor    public ExternalIdentifierLookup,
180cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    public ExternalSLocEntrySource
181cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor{
182e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregorpublic:
183c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  enum ASTReadResult { Success, Failure, IgnorePCH };
1841d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl  /// \brief Types of AST files.
1851d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl  enum ASTFileType {
1861d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl    Module,   ///< File is a module proper.
1871d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl    PCH,      ///< File is a PCH file treated as such.
1881d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl    Preamble, ///< File is a PCH file treated as the preamble.
1891d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl    MainFile  ///< File is a PCH file treated as the actual main file.
1901d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl  };
191d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  friend class PCHValidator;
192d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl  friend class ASTDeclReader;
193c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  friend class ASTStmtReader;
19495f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  friend class ASTIdentifierIterator;
195c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  friend class ASTIdentifierLookupTrait;
196c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  friend class TypeLocReader;
197f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  friend class ASTWriter;
198f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  friend class ASTUnit; // ASTUnit needs to remap source locations.
199e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregorprivate:
200c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief The receiver of some callbacks invoked by ASTReader.
201571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  llvm::OwningPtr<ASTReaderListener> Listener;
2021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20330c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl  /// \brief The receiver of deserialization events.
204571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  ASTDeserializationListener *DeserializationListener;
20530c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl
20611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  SourceManager &SourceMgr;
20711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  FileManager &FileMgr;
20811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  Diagnostic &Diags;
2091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
210668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief The semantic analysis object that will be processing the
2113c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// AST files and the translation unit that uses it.
212668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  Sema *SemaObj;
213668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
21414f79002e58556798e86168c63e48d533287eda5Douglas Gregor  /// \brief The preprocessor that will be loading the source file.
21511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  Preprocessor *PP;
21614f79002e58556798e86168c63e48d533287eda5Douglas Gregor
2173c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The AST context into which we'll read the AST files.
218d1d64a027554b635d644957ef071ec04ea1f7063Chris Lattner  ASTContext *Context;
21952e7108f51a4a9f4d6e84f33fb594d06e1d79560Douglas Gregor
2200af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor  /// \brief The AST consumer.
2210af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor  ASTConsumer *Consumer;
2220af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor
223b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis  /// \brief AST buffers for chained PCHs created and stored in memory.
224b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis  /// First (not depending on another) PCH in chain is in front.
2250acc4ea40d2a75fbaf385e095a252f59078c7b94Sebastian Redl  std::vector<llvm::MemoryBuffer *> ASTBuffers;
226b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis
227a866e652875c61f09ac29c2f44009ce9f2a25cf2Sebastian Redl  /// \brief Information that is needed for every module.
2289137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl  struct PerFileData {
2291d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl    PerFileData(ASTFileType Ty);
230501c1036560bb407f9be6834931253f0929cca86Douglas Gregor    ~PerFileData();
2319137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
232301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    // === General information ===
2332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2341d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl    /// \brief The type of this AST file.
2351d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl    ASTFileType Type;
2361d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl
2373c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// \brief The file name of the AST file.
2389137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    std::string FileName;
2390a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor
2409137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    /// \brief The memory buffer that stores the data associated with
2413c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// this AST file.
2429137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    llvm::OwningPtr<llvm::MemoryBuffer> Buffer;
2432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
244301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// \brief The size of this file, in bits.
245301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    uint64_t SizeInBits;
246301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
247301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// \brief The bitstream reader from which we'll read the AST file.
248301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    llvm::BitstreamReader StreamFile;
249301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
250301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// \brief The main bitstream cursor for the main block.
251301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    llvm::BitstreamCursor Stream;
252301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
253f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    /// \brief The source location where this module was first imported.
254f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    SourceLocation ImportLoc;
255f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor
256f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    /// \brief The first source location in this module.
257f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    SourceLocation FirstLoc;
258f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor
259301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    // === Source Locations ===
260301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
2619137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    /// \brief Cursor used to read source location entries.
2629137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    llvm::BitstreamCursor SLocEntryCursor;
2639137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
2643c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// \brief The number of source location entries in this AST file.
2659137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    unsigned LocalNumSLocEntries;
2669137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
267f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    /// \brief The base ID in the source manager's view of this module.
268f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    int SLocEntryBaseID;
269f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor
270f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    /// \brief The base offset in the source manager's view of this module.
271f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    unsigned SLocEntryBaseOffset;
272f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor
273518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl    /// \brief Offsets for all of the source location entries in the
2743c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// AST file.
275f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    const uint32_t *SLocEntryOffsets;
276518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl
2774cdb0e2a2e9d93805e5ceaf8bc7018bdd166aec1Argyrios Kyrtzidis    /// \brief The number of source location file entries in this AST file.
2784cdb0e2a2e9d93805e5ceaf8bc7018bdd166aec1Argyrios Kyrtzidis    unsigned LocalNumSLocFileEntries;
2794cdb0e2a2e9d93805e5ceaf8bc7018bdd166aec1Argyrios Kyrtzidis
2804cdb0e2a2e9d93805e5ceaf8bc7018bdd166aec1Argyrios Kyrtzidis    /// \brief Offsets for all of the source location file entries in the
2814cdb0e2a2e9d93805e5ceaf8bc7018bdd166aec1Argyrios Kyrtzidis    /// AST file.
2824cdb0e2a2e9d93805e5ceaf8bc7018bdd166aec1Argyrios Kyrtzidis    const uint32_t *SLocFileOffsets;
2834cdb0e2a2e9d93805e5ceaf8bc7018bdd166aec1Argyrios Kyrtzidis
284f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    /// \brief Remapping table for source locations in this module.
285f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    ContinuousRangeMap<uint32_t, int, 2> SLocRemap;
2864ee5a6f9bd82ab3c1a4bdacc0caefe7d5f8bd37aSebastian Redl
287301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    // === Identifiers ===
2882da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl
2893c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// \brief The number of identifiers in this AST file.
2902da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    unsigned LocalNumIdentifiers;
2912da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl
2922da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    /// \brief Offsets into the identifier table data.
2932da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    ///
2942da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    /// This array is indexed by the identifier ID (-1), and provides
2952da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    /// the offset into IdentifierTableData where the string data is
2962da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    /// stored.
2972da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    const uint32_t *IdentifierOffsets;
29812d6da0675fa7df09e3f078995774b350e3a4652Sebastian Redl
299cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    /// \brief Actual data for the on-disk hash table of identifiers.
30093fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl    ///
301301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// This pointer points into a memory buffer, where the on-disk hash
302301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// table for identifiers actually lives.
30393fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl    const char *IdentifierTableData;
30493fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl
30593fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl    /// \brief A pointer to an on-disk hash table of opaque type
30693fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl    /// IdentifierHashTable.
30793fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl    void *IdentifierLookupTable;
30804e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl
309301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    // === Macros ===
310301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
3118db9faed418ea743f55c31e1ccecadbb23bd55b7Sebastian Redl    /// \brief The cursor to the start of the preprocessor block, which stores
3128db9faed418ea743f55c31e1ccecadbb23bd55b7Sebastian Redl    /// all of the macro definitions.
3138db9faed418ea743f55c31e1ccecadbb23bd55b7Sebastian Redl    llvm::BitstreamCursor MacroCursor;
3148db9faed418ea743f55c31e1ccecadbb23bd55b7Sebastian Redl
315ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    /// \brief The offset of the start of the set of defined macros.
316ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    uint64_t MacroStartOffset;
317ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor
3184800a5c79023271408af49797e09be32aca93232Douglas Gregor    // === Detailed PreprocessingRecord ===
3194800a5c79023271408af49797e09be32aca93232Douglas Gregor
3204800a5c79023271408af49797e09be32aca93232Douglas Gregor    /// \brief The cursor to the start of the (optional) detailed preprocessing
3214800a5c79023271408af49797e09be32aca93232Douglas Gregor    /// record block.
3224800a5c79023271408af49797e09be32aca93232Douglas Gregor    llvm::BitstreamCursor PreprocessorDetailCursor;
3234800a5c79023271408af49797e09be32aca93232Douglas Gregor
3244800a5c79023271408af49797e09be32aca93232Douglas Gregor    /// \brief The offset of the start of the preprocessor detail cursor.
3254800a5c79023271408af49797e09be32aca93232Douglas Gregor    uint64_t PreprocessorDetailStartOffset;
3264800a5c79023271408af49797e09be32aca93232Douglas Gregor
32704e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl    /// \brief The number of macro definitions in this file.
32804e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl    unsigned LocalNumMacroDefinitions;
3294800a5c79023271408af49797e09be32aca93232Douglas Gregor
33004e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl    /// \brief Offsets of all of the macro definitions in the preprocessing
3313c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// record in the AST file.
33204e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl    const uint32_t *MacroDefinitionOffsets;
333301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
334cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    // === Header search information ===
335cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
336cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    /// \brief The number of local HeaderFileInfo structures.
337cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    unsigned LocalNumHeaderFileInfos;
338cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
339cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    /// \brief Actual data for the on-disk hash table of header file
340cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    /// information.
341cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    ///
342cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    /// This pointer points into a memory buffer, where the on-disk hash
343cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    /// table for header file information actually lives.
344cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    const char *HeaderFileInfoTableData;
345cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
346cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    /// \brief The on-disk hash table that contains information about each of
347cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    /// the header files.
348cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    void *HeaderFileInfoTable;
349cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
350301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    // === Selectors ===
351301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
352301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// \brief The number of selectors new to this file.
353301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    ///
354301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// This is the number of entries in SelectorOffsets.
355301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    unsigned LocalNumSelectors;
356301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
357301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// \brief Offsets into the selector lookup table's data array
358301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// where each selector resides.
359301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    const uint32_t *SelectorOffsets;
360301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
361301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// \brief A pointer to the character data that comprises the selector table
362301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    ///
363301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// The SelectorOffsets table refers into this memory.
364301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    const unsigned char *SelectorLookupTableData;
365320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian
366059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl    /// \brief A pointer to an on-disk hash table of opaque type
3673c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// ASTSelectorLookupTable.
368059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl    ///
369725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl    /// This hash table provides the IDs of all selectors, and the associated
370725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl    /// instance and factory methods.
371725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl    void *SelectorLookupTable;
372059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl
373c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    /// \brief Method selectors used in a @selector expression. Used for
374c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    /// implementation of -Wselector.
375686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    SmallVector<uint64_t, 64> ReferencedSelectorsData;
376c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl
377301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    // === Declarations ===
378301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
379301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block. It
380301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// has read all the abbreviations at the start of the block and is ready to
381301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// jump around with these in context.
382301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    llvm::BitstreamCursor DeclsCursor;
383059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl
384301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// \brief The number of declarations in this AST file.
385301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    unsigned LocalNumDecls;
386725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl
387301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// \brief Offset of each declaration within the bitstream, indexed
388301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// by the declaration ID (-1).
389301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    const uint32_t *DeclOffsets;
390301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
391c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    /// \brief A snapshot of the pending instantiations in the chain.
392c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    ///
393c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    /// This record tracks the instantiations that Sema has to perform at the
394c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    /// end of the TU. It consists of a pair of values for every pending
395c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    /// instantiation where the first value is the ID of the decl and the second
396c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    /// is the instantiation location.
397686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    SmallVector<uint64_t, 64> PendingInstantiations;
398c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl
3997c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor    /// \brief The number of C++ base specifier sets in this AST file.
4007c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor    unsigned LocalNumCXXBaseSpecifiers;
4017c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor
4027c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor    /// \brief Offset of each C++ base specifier set within the bitstream,
4037c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor    /// indexed by the C++ base specifier set ID (-1).
4047c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor    const uint32_t *CXXBaseSpecifiersOffsets;
4057c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor
406301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    // === Types ===
407301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
408301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// \brief The number of types in this AST file.
409301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    unsigned LocalNumTypes;
410301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
411301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// \brief Offset of each type within the bitstream, indexed by the
412301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// type ID, or the representation of a Type*.
413301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    const uint32_t *TypeOffsets;
414301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
415301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    // === Miscellaneous ===
416301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl
417f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    /// \brief Diagnostic IDs and their mappings that the user changed.
418686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    SmallVector<uint64_t, 8> PragmaDiagMappings;
419f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor
420301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// \brief The AST stat cache installed for this file, if any.
421725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl    ///
422301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// The dynamic type of this stat cache is always ASTStatCache
423301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    void *StatCache;
424a866e652875c61f09ac29c2f44009ce9f2a25cf2Sebastian Redl
425301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// \brief The number of preallocated preprocessing entities in the
426301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    /// preprocessing record.
427301c9b0b6722293f1b9d870815ae11e1ffc3245dSebastian Redl    unsigned NumPreallocatedPreprocessingEntities;
428a866e652875c61f09ac29c2f44009ce9f2a25cf2Sebastian Redl
429a866e652875c61f09ac29c2f44009ce9f2a25cf2Sebastian Redl    /// \brief The next module in source order.
430a866e652875c61f09ac29c2f44009ce9f2a25cf2Sebastian Redl    PerFileData *NextInSource;
431a866e652875c61f09ac29c2f44009ce9f2a25cf2Sebastian Redl
432a866e652875c61f09ac29c2f44009ce9f2a25cf2Sebastian Redl    /// \brief All the modules that loaded this one. Can contain NULL for
433a866e652875c61f09ac29c2f44009ce9f2a25cf2Sebastian Redl    /// directly loaded modules.
434686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    SmallVector<PerFileData *, 1> Loaders;
4359137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl  };
4369137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
437a866e652875c61f09ac29c2f44009ce9f2a25cf2Sebastian Redl  /// \brief All loaded modules, indexed by name.
438a866e652875c61f09ac29c2f44009ce9f2a25cf2Sebastian Redl  llvm::StringMap<PerFileData*> Modules;
439a866e652875c61f09ac29c2f44009ce9f2a25cf2Sebastian Redl
440a866e652875c61f09ac29c2f44009ce9f2a25cf2Sebastian Redl  /// \brief The first module in source order.
441a866e652875c61f09ac29c2f44009ce9f2a25cf2Sebastian Redl  PerFileData *FirstInSource;
442a866e652875c61f09ac29c2f44009ce9f2a25cf2Sebastian Redl
4433c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The chain of AST files. The first entry is the one named by the
4449137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl  /// user, the last one is the one that doesn't depend on anything further.
445190faf7c30890479925193b074571e5dc30c3f53Sebastian Redl  /// That is, the entry I was created with -include-pch I+1.
446686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<PerFileData*, 2> Chain;
4479137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
4484ee5a6f9bd82ab3c1a4bdacc0caefe7d5f8bd37aSebastian Redl  /// \brief SLocEntries that we're going to preload.
449686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<int, 64> PreloadSLocEntries;
450f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor
451f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// \brief A map of negated SLocEntryIDs to the modules containing them.
452f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  ContinuousRangeMap<unsigned, PerFileData*, 64> GlobalSLocEntryMap;
4534ee5a6f9bd82ab3c1a4bdacc0caefe7d5f8bd37aSebastian Redl
4543c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Types that have already been loaded from the chain.
4551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// When the pointer at index I is non-NULL, the type with
4573c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// ID = (I + 1) << FastQual::Width has already been loaded
4580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::vector<QualType> TypesLoaded;
4592cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
460e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  typedef ContinuousRangeMap<serialization::TypeID,
461e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner      std::pair<PerFileData *, int32_t>, 4>
462e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner    GlobalTypeMapType;
463e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner
464e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  /// \brief Mapping from global type IDs to the module in which the
465e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  /// type resides along with the offset that should be added to the
466e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  /// global type ID to produce a local ID.
467e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  GlobalTypeMapType GlobalTypeMap;
468e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner
4695d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// \brief Map that provides the ID numbers of each type within the
4705d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// output stream, plus those deserialized from a chained PCH.
4715d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  ///
4725d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// The ID numbers of types are consecutive (in order of discovery)
4735d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// and start at 1. 0 is reserved for NULL. When types are actually
4745d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// stored in the stream, the ID number is shifted by 2 bits to
4755d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// allow for the const/volatile qualifiers.
4765d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  ///
4775d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// Keys in the map never have const/volatile qualifiers.
4785d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  serialization::TypeIdxMap TypeIdxs;
4795d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis
4803c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Declarations that have already been loaded from the chain.
4812cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
4828f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  /// When the pointer at index I is non-NULL, the declaration with ID
4838f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  /// = I + 1 has already been loaded.
4848f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  std::vector<Decl *> DeclsLoaded;
4852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
48696e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor  typedef ContinuousRangeMap<serialization::DeclID,
48796e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor                             std::pair<PerFileData *, int32_t>, 4>
48896e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor    GlobalDeclMapType;
48967268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor
49096e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor  /// \brief Mapping from global declaration IDs to the module in which the
49196e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor  /// declaration resides along with the offset that should be added to the
49296e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor  /// global declaration ID to produce a local ID.
49396e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor  GlobalDeclMapType GlobalDeclMap;
49496e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor
4957b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  typedef std::pair<PerFileData *, uint64_t> FileOffset;
496686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<FileOffset, 2> FileOffsetsTy;
4977b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy>
4987b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis      DeclUpdateOffsetsMap;
49996e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor
5007b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  /// \brief Declarations that have modifications residing in a later file
5017b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  /// in the chain.
5027b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  DeclUpdateOffsetsMap DeclUpdateOffsets;
5037b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis
5048538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  typedef llvm::DenseMap<serialization::DeclID,
5058538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl                         std::pair<PerFileData *, uint64_t> >
5060b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl      DeclReplacementMap;
5070b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl  /// \brief Declarations that have been replaced in a later file in the chain.
5080b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl  DeclReplacementMap ReplacedDecls;
5090b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl
5100fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  /// \brief Information about the contents of a DeclContext.
5110fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  struct DeclContextInfo {
512074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis    void *NameLookupTableData; // a ASTDeclContextNameLookupTable.
513eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis    const serialization::KindDeclIDPair *LexicalDecls;
514681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl    unsigned NumLexicalDecls;
5150fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  };
516e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // In a full chain, there could be multiple updates to every decl context,
517e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // so this is a vector. However, typically a chain is only two elements long,
518e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // with only one file containing updates, so there will be only one update
519e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // per decl context.
520686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<DeclContextInfo, 1> DeclContextInfos;
5210fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  typedef llvm::DenseMap<const DeclContext *, DeclContextInfos>
522e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl      DeclContextOffsetsMap;
523e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // Updates for visible decls can occur for other contexts than just the
524e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // TU, and when we read those update records, the actual context will not
525e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // be available yet (unless it's the TU), so have this pending map using the
526e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // ID as a key. It will be realized when the context is actually loaded.
527686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<void *, 1> DeclContextVisibleUpdates;
528e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
529e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl      DeclContextVisibleUpdatesPending;
5302cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
5312cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Offsets of the lexical and visible declarations for each
5322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// DeclContext.
5332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  DeclContextOffsetsMap DeclContextOffsets;
5342cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
535e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  /// \brief Updates to the visible declarations of declaration contexts that
536e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  /// haven't been loaded yet.
537e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  DeclContextVisibleUpdatesPending PendingVisibleUpdates;
538e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl
539686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<CXXRecordDecl *, 4> ForwardRefs;
540134db1fff5653c164ef41c898943521c49f6ebabArgyrios Kyrtzidis  typedef llvm::DenseMap<const CXXRecordDecl *, ForwardRefs>
541134db1fff5653c164ef41c898943521c49f6ebabArgyrios Kyrtzidis      PendingForwardRefsMap;
542134db1fff5653c164ef41c898943521c49f6ebabArgyrios Kyrtzidis  /// \brief Forward references that have a definition but the definition decl
543134db1fff5653c164ef41c898943521c49f6ebabArgyrios Kyrtzidis  /// is still initializing. When the definition gets read it will update
544134db1fff5653c164ef41c898943521c49f6ebabArgyrios Kyrtzidis  /// the DefinitionData pointer of all pending references.
545134db1fff5653c164ef41c898943521c49f6ebabArgyrios Kyrtzidis  PendingForwardRefsMap PendingForwardRefs;
546134db1fff5653c164ef41c898943521c49f6ebabArgyrios Kyrtzidis
5478538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  typedef llvm::DenseMap<serialization::DeclID, serialization::DeclID>
5488538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl      FirstLatestDeclIDMap;
549a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis  /// \brief Map of first declarations from a chained PCH that point to the
5503c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// most recent declarations in another AST file.
551a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis  FirstLatestDeclIDMap FirstLatestDeclIDs;
552a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis
553681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl  /// \brief Read the records that describe the contents of declcontexts.
554681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl  bool ReadDeclContextStorage(llvm::BitstreamCursor &Cursor,
555681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl                              const std::pair<uint64_t, uint64_t> &Offsets,
556681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl                              DeclContextInfo &Info);
557681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl
5582b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// \brief A vector containing identifiers that have already been
5592b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// loaded.
5602b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  ///
5612b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// If the pointer at index I is non-NULL, then it refers to the
5622b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// IdentifierInfo for the identifier with ID=I+1 that has already
5632b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// been loaded.
5642b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  std::vector<IdentifierInfo *> IdentifiersLoaded;
565afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor
56667268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  typedef ContinuousRangeMap<serialization::IdentID,
56767268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor                             std::pair<PerFileData *, int32_t>, 4>
56867268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor    GlobalIdentifierMapType;
56967268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor
57067268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  /// \brief Mapping from global identifer IDs to the module in which the
57167268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  /// identifier resides along with the offset that should be added to the
57267268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  /// global identifier ID to produce a local ID.
57367268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  GlobalIdentifierMapType GlobalIdentifierMap;
57467268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor
5751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief A vector containing selectors that have already been loaded.
57683941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  ///
57783941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// This vector is indexed by the Selector ID (-1). NULL selector
57883941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// entries indicate that the particular selector ID has not yet
57983941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// been loaded.
580686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Selector, 16> SelectorsLoaded;
581725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl
58296958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  typedef ContinuousRangeMap<serialization::SelectorID,
58396958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor                             std::pair<PerFileData *, int32_t>, 4>
58496958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor    GlobalSelectorMapType;
58596958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor
58696958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  /// \brief Mapping from global selector IDs to the module in which the
58796958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  /// selector resides along with the offset that should be added to the
58896958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  /// global selector ID to produce a local ID.
58996958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  GlobalSelectorMapType GlobalSelectorMap;
59096958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor
5916a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor  /// \brief The macro definitions we have already loaded.
592686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<MacroDefinition *, 16> MacroDefinitionsLoaded;
593892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
59414ad03b6f4350f062256757efc4149a7df94bdf9Douglas Gregor  typedef ContinuousRangeMap<serialization::MacroID,
59514ad03b6f4350f062256757efc4149a7df94bdf9Douglas Gregor                             std::pair<PerFileData *, int32_t>, 4>
59614ad03b6f4350f062256757efc4149a7df94bdf9Douglas Gregor    GlobalMacroDefinitionMapType;
59714ad03b6f4350f062256757efc4149a7df94bdf9Douglas Gregor
59814ad03b6f4350f062256757efc4149a7df94bdf9Douglas Gregor  /// \brief Mapping from global macro definition IDs to the module in which the
59914ad03b6f4350f062256757efc4149a7df94bdf9Douglas Gregor  /// selector resides along with the offset that should be added to the
60014ad03b6f4350f062256757efc4149a7df94bdf9Douglas Gregor  /// global selector ID to produce a local ID.
60114ad03b6f4350f062256757efc4149a7df94bdf9Douglas Gregor  GlobalMacroDefinitionMapType GlobalMacroDefinitionMap;
60214ad03b6f4350f062256757efc4149a7df94bdf9Douglas Gregor
603295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// \brief Mapping from identifiers that represent macros whose definitions
604295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// have not yet been deserialized to the global offset where the macro
605295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// record resides.
606295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  llvm::DenseMap<IdentifierInfo *, uint64_t> UnreadMacroRecordOffsets;
6074c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
6084c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  typedef ContinuousRangeMap<unsigned, std::pair<PerFileData *, int>, 4>
6094c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    GlobalPreprocessedEntityMapType;
6104c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
6114c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// \brief Mapping from global preprocessing entity IDs to the module in
6124c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// which the preprocessed entity resides along with the offset that should be
6134c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// added to the global preprocessing entitiy ID to produce a local ID.
6144c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
6154c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
616892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \name CodeGen-relevant special data
617892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief Fields containing data that is relevant to CodeGen.
618892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@{
619892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
620892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all declarations that fulfill the criteria of
621892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// "interesting" decls.
622892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
623892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// This contains the data loaded from all EXTERNAL_DEFINITIONS blocks in the
624892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// chain. The referenced declarations are deserialized and passed to the
625892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// consumer eagerly.
626686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> ExternalDefinitions;
627fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor
628892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all tentative definitions stored in the the chain.
629892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
630892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema keeps track of all tentative definitions in a TU because it has to
631892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// complete them and pass them on to CodeGen. Thus, tentative definitions in
632892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// the PCH chain must be eagerly deserialized.
633686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> TentativeDefinitions;
634892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
635892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are
636892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// used.
637892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
638892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// CodeGen has to emit VTables for these records, so they have to be eagerly
639892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// deserialized.
640686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 64> VTableUses;
641892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
642892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@}
643892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
644892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \name Diagnostic-relevant special data
645892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief Fields containing data that is used for generating diagnostics
646892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@{
647892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
648892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief A snapshot of Sema's unused file-scoped variable tracking, for
649892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// generating warnings.
650686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> UnusedFileScopedDecls;
6514c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor
652ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt  /// \brief A list of all the delegating constructors we've seen, to diagnose
653ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt  /// cycles.
654686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> DelegatingCtorDecls;
655ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt
656892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief A snapshot of Sema's weak undeclared identifier tracking, for
657892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// generating warnings.
658686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
65914c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor
660892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of type aliases for ext_vectors that exist in the chain.
661892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
662892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
663686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> ExtVectorDecls;
664b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor
665892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@}
666d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis
667892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \name Sema-relevant special data
668892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief Fields containing data that is used for semantic analysis
669892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@{
670892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
671892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all locally scoped external decls in the chain.
672892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
673892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema tracks these to validate that the types are consistent across all
674892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// local external declarations.
675686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> LocallyScopedExternalDecls;
676d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis
677892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all dynamic class declarations in the chain.
678892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
679892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema tracks these because it checks for the key functions being defined
680892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// at the end of the TU, in which case it directs CodeGen to emit the VTable.
681686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> DynamicClasses;
682892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
683892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of the declarations Sema stores directly.
684892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
685892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema tracks a few important decls, such as namespace std, directly.
686686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> SemaDeclRefs;
68776c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis
688e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// \brief The IDs of the types ASTContext stores directly.
689e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  ///
690e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// The AST context tracks a few important types, such as va_list, directly.
691686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> SpecialTypes;
692e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl
69314b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  /// \brief The IDs of CUDA-specific declarations ASTContext stores directly.
69414b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  ///
69514b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  /// The AST context tracks a few important decls, currently cudaConfigureCall,
69614b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  /// directly.
697686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
69814b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne
69984bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne  /// \brief The floating point pragma option settings.
700686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 1> FPPragmaOptions;
70184bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne
70284bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne  /// \brief The OpenCL extension settings.
703686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 1> OpenCLExtensions;
70484bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne
705d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  /// \brief A list of the namespaces we've seen.
706686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> KnownNamespaces;
707d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor
708892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@}
709892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
7103c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The original file name that was used to build the primary AST file,
7113c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// which may have been modified for relocatable-pch support.
712b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor  std::string OriginalFileName;
713b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor
7143c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The actual original file name that was used to build the primary
7153c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// AST file.
7167b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar  std::string ActualOriginalFileName;
7177b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar
71831d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor  /// \brief The file ID for the original file that was used to build the
71931d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor  /// primary AST file.
72031d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor  FileID OriginalFileID;
72131d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor
7228e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  /// \brief The directory that the PCH was originally created in. Used to
7238e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  /// allow resolving headers even after headers+PCH was moved to a new path.
7248e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  std::string OriginalDir;
7258e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis
7268e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  /// \brief The directory that the PCH we are reading is stored in.
7278e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  std::string CurrentDir;
7288e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis
729e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \brief Whether this precompiled header is a relocatable PCH file.
730e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  bool RelocatablePCH;
7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief The system include root to be used when loading the
733e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// precompiled header.
734e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  const char *isysroot;
7351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
736fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// \brief Whether to disable the normal validation performed on precompiled
737fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// headers when they are loaded.
738fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  bool DisableValidation;
739fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor
7408ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// \brief Whether to disable the use of stat caches in AST files.
7418ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  bool DisableStatCache;
7428ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor
7433c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Mapping from switch-case IDs in the chain to switch-case statements
744e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  ///
745e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// Statements usually don't have IDs, but switch cases need them, so that the
746e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// switch statement can refer to them.
747025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  std::map<unsigned, SwitchCase *> SwitchCaseStmts;
748025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
74956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// \brief Mapping from opaque value IDs to OpaqueValueExprs.
75056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  std::map<unsigned, OpaqueValueExpr*> OpaqueValueExprs;
75156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
7524fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  /// \brief The number of stat() calls that hit/missed the stat
7534fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  /// cache.
7544fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  unsigned NumStatHits, NumStatMisses;
7554fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor
7567f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// \brief The number of source location entries de-serialized from
7577f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// the PCH file.
7587f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  unsigned NumSLocEntriesRead;
7597f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor
7603c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The number of source location entries in the chain.
761518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl  unsigned TotalNumSLocEntries;
762518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl
7633e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  /// \brief The number of statements (and expressions) de-serialized
7643c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// from the chain.
7653e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  unsigned NumStatementsRead;
7663e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor
7673e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  /// \brief The total number of statements (and expressions) stored
7683c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// in the chain.
7693e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  unsigned TotalNumStatements;
7703e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor
7713c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The number of macros de-serialized from the chain.
77237e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor  unsigned NumMacrosRead;
7732512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor
7743c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The total number of macros stored in the chain.
775fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned TotalNumMacros;
776fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl
777725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl  /// \brief The number of selectors that have been read.
778725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl  unsigned NumSelectorsRead;
77983941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor
780fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The number of method pool entries that have been read.
781fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned NumMethodPoolEntriesRead;
78283941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor
783fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The number of times we have looked up a selector in the method
784fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// pool and not found anything interesting.
785fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned NumMethodPoolMisses;
786fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl
787fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The total number of method pool entries in the selector table.
788fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned TotalNumMethodPoolEntries;
78937e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor
7902512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  /// Number of lexical decl contexts read/total.
7912512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts;
7922512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor
7932512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  /// Number of visible decl contexts read/total.
7942512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts;
79529ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis
79629ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// \brief Number of Decl/types that are currently deserializing.
79729ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  unsigned NumCurrentElementsDeserializing;
7981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief An IdentifierInfo that has been loaded but whose top-level
800d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// declarations of the same name have not (yet) been loaded.
801d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  struct PendingIdentifierInfo {
802d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor    IdentifierInfo *II;
803686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    SmallVector<uint32_t, 4> DeclIDs;
804d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  };
8051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8063c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of identifiers that were read while the AST reader was
8071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// (recursively) loading declarations.
8081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
809d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// The declarations on the identifier chain for these identifiers will be
810d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// loaded once the recursive loading has completed.
811d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  std::deque<PendingIdentifierInfo> PendingIdentifierInfos;
8121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
813c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// \brief Contains declarations and definitions that will be
814c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// "interesting" to the ASTConsumer, when we get that AST consumer.
815c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  ///
816c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// "Interesting" declarations are those that have data that may
817c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// need to be emitted, such as inline function definitions or
818c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// Objective-C protocols.
819bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis  std::deque<Decl *> InterestingDecls;
820c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor
8210895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis  /// \brief We delay loading of the previous declaration chain to avoid
8220895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis  /// deeply nested calls when there are many redeclarations.
8230895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis  std::deque<std::pair<Decl *, serialization::DeclID> > PendingPreviousDecls;
8240895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis
8250895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis  /// \brief Ready to load the previous declaration of the given Decl.
8260895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis  void loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID);
8270895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis
828919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief When reading a Stmt tree, Stmt operands are placed in this stack.
829686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Stmt *, 16> StmtStack;
830919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
831919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief What kind of records we are reading.
832919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  enum ReadingKind {
833919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    Read_Decl, Read_Type, Read_Stmt
834919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  };
835919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
836919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief What kind of records we are reading.
837919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  ReadingKind ReadingKind;
838919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
839919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief RAII object to change the reading kind.
840919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  class ReadingKindTracker {
841c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl    ASTReader &Reader;
842919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    enum ReadingKind PrevKind;
843919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
844919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    ReadingKindTracker(const ReadingKindTracker&); // do not implement
845919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    ReadingKindTracker &operator=(const ReadingKindTracker&);// do not implement
846919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
847919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  public:
848c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl    ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
849919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis      : Reader(reader), PrevKind(Reader.ReadingKind) {
850919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis      Reader.ReadingKind = newKind;
851919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    }
852919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
853919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
854919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  };
855919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
8563c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief All predefines buffers in the chain, to be treated as if
8577e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// concatenated.
8587e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  PCHPredefinesBlocks PCHPredefinesBuffers;
85992b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor
860e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// \brief Suggested contents of the predefines buffer, after this
861e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// PCH file has been processed.
862e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  ///
863e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// In most cases, this string will be empty, because the predefines
864e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// buffer computed to build the PCH file will be identical to the
865e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// predefines buffer computed from the command line. However, when
866e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// there are differences that the PCH reader can work around, this
867e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// predefines buffer may contain additional definitions.
868e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  std::string SuggestedPredefines;
8691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
870919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads a statement from the specified cursor.
871c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  Stmt *ReadStmtFromStream(PerFileData &F);
872919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
873b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  /// \brief Get a FileEntry out of stored-in-PCH filename, making sure we take
874b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  /// into account all the necessary relocations.
875686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  const FileEntry *getFileEntry(StringRef filename);
876b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis
877e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  void MaybeAddSystemRootToFilename(std::string &Filename);
8781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
879686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  ASTReadResult ReadASTCore(StringRef FileName, ASTFileType Type);
880571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  ASTReadResult ReadASTBlock(PerFileData &F);
8817e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  bool CheckPredefinesBuffers();
882686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  bool ParseLineTable(PerFileData &F, SmallVectorImpl<uint64_t> &Record);
883c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReadResult ReadSourceManagerBlock(PerFileData &F);
884f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  ASTReadResult ReadSLocEntryRecord(int ID);
885f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  llvm::BitstreamCursor &SLocCursorForID(int ID);
886c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  SourceLocation getImportLocation(PerFileData *F);
887686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  bool ParseLanguageOptions(const SmallVectorImpl<uint64_t> &Record);
888aaec0aa844781dc7c3462ba140e004e589ccd355Sebastian Redl
889c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  struct RecordLocation {
890c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    RecordLocation(PerFileData *M, uint64_t O)
891c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl      : F(M), Offset(O) {}
892c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    PerFileData *F;
893c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    uint64_t Offset;
894c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  };
895aaec0aa844781dc7c3462ba140e004e589ccd355Sebastian Redl
896aaec0aa844781dc7c3462ba140e004e589ccd355Sebastian Redl  QualType ReadTypeRecord(unsigned Index);
897aaec0aa844781dc7c3462ba140e004e589ccd355Sebastian Redl  RecordLocation TypeCursorForIndex(unsigned Index);
8982cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  void LoadedDecl(unsigned Index, Decl *D);
8998538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Decl *ReadDeclRecord(unsigned Index, serialization::DeclID ID);
9008538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  RecordLocation DeclCursorForIndex(unsigned Index, serialization::DeclID ID);
9012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
902bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis  void PassInterestingDeclsToConsumer();
903bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis
904a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  /// \brief Produce an error diagnostic and return true.
905a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  ///
906a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  /// This routine should only be used for fatal errors that have to
9073c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// do with non-routine failures (e.g., corrupted AST file).
908686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void Error(StringRef Msg);
909686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
910686775deca8b8685eb90801495880e3abdd844c2Chris Lattner             StringRef Arg2 = StringRef());
911a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor
912c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader(const ASTReader&); // do not implement
913c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader &operator=(const ASTReader &); // do not implement
9142cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorpublic:
915686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<uint64_t, 64> RecordData;
9162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
9173c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Load the AST file and validate its contents against the given
91811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// Preprocessor.
919e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
920e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param PP the preprocessor associated with the context in which this
921e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// precompiled header will be loaded.
922e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
923e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param Context the AST context that this precompiled header will be
924e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// loaded into.
925e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
926e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param isysroot If non-NULL, the system include path specified by the
927e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// user. This is only used with relocatable PCH files. If non-NULL,
928e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// a relocatable PCH file will use the default path "/".
929fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  ///
9303c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param DisableValidation If true, the AST reader will suppress most
931fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// of its regular consistency checking, allowing the use of precompiled
932fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// headers that cannot be determined to be compatible.
9338ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  ///
9348ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// \param DisableStatCache If true, the AST reader will ignore the
9358ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// stat cache in the AST files. This performance pessimization can
9368ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// help when an AST file is being used in cases where the
9378ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// underlying files in the file system may have changed, but
9388ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// parsing should still continue.
939c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader(Preprocessor &PP, ASTContext *Context, const char *isysroot = 0,
9408ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor            bool DisableValidation = false, bool DisableStatCache = false);
9411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9423c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Load the AST file without using any pre-initialized Preprocessor.
94311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
94411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// The necessary information to initialize a Preprocessor later can be
945571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  /// obtained by setting a ASTReaderListener.
946e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
9473c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param SourceMgr the source manager into which the AST file will be loaded
948e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
9493c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param FileMgr the file manager into which the AST file will be loaded.
950e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
951e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param Diags the diagnostics system to use for reporting errors and
9523c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// warnings relevant to loading the AST file.
953e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
954e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param isysroot If non-NULL, the system include path specified by the
955e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// user. This is only used with relocatable PCH files. If non-NULL,
956e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// a relocatable PCH file will use the default path "/".
957fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  ///
9583c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param DisableValidation If true, the AST reader will suppress most
959fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// of its regular consistency checking, allowing the use of precompiled
960fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// headers that cannot be determined to be compatible.
9618ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  ///
9628ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// \param DisableStatCache If true, the AST reader will ignore the
9638ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// stat cache in the AST files. This performance pessimization can
9648ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// help when an AST file is being used in cases where the
9658ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// underlying files in the file system may have changed, but
9668ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// parsing should still continue.
967389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis  ASTReader(SourceManager &SourceMgr, FileManager &FileMgr,
968fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor            Diagnostic &Diags, const char *isysroot = 0,
9698ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor            bool DisableValidation = false, bool DisableStatCache = false);
970c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ~ASTReader();
9712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
972b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor  /// \brief Load the precompiled header designated by the given file
973b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor  /// name.
9741d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl  ASTReadResult ReadAST(const std::string &FileName, ASTFileType Type);
9751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
976b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  /// \brief Checks that no file that is stored in PCH is out-of-sync with
977b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  /// the actual file in the file system.
978b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  ASTReadResult validateFileEntries();
979b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis
9803c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set the AST callbacks listener.
981571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  void setListener(ASTReaderListener *listener) {
98211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    Listener.reset(listener);
98311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
9841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9853c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set the AST deserialization listener.
986571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  void setDeserializationListener(ASTDeserializationListener *Listener);
98730c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl
98811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Set the Preprocessor to use.
9896a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor  void setPreprocessor(Preprocessor &pp);
9901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
99111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Sets and initializes the given Context.
99211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  void InitializeContext(ASTContext &Context);
9932cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
994b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis  /// \brief Set AST buffers for chained PCHs created and stored in memory.
995b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis  /// First (not depending on another) PCH in chain is first in array.
996b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis  void setASTMemoryBuffers(llvm::MemoryBuffer **bufs, unsigned numBufs) {
997b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis    ASTBuffers.clear();
998b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis    ASTBuffers.insert(ASTBuffers.begin(), bufs, bufs + numBufs);
999b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis  }
1000b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis
10013c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Retrieve the name of the named (primary) AST file
10029137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl  const std::string &getFileName() const { return Chain[0]->FileName; }
1003e19944c93961b7618f4f3f3185f698f46369ea54Steve Naroff
10041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the name of the original source file name
1005b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor  const std::string &getOriginalSourceFile() { return OriginalFileName; }
1006b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor
10073c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Retrieve the name of the original source file name directly from
10083c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// the AST file, without actually loading the AST file.
10093c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  static std::string getOriginalSourceFile(const std::string &ASTFileName,
1010389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis                                           FileManager &FileMgr,
101193ebb1ba9f35ab5e7bff37c471baeb360eeb0b04Daniel Dunbar                                           Diagnostic &Diags);
1012b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor
1013e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// \brief Returns the suggested contents of the predefines buffer,
1014e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// which contains a (typically-empty) subset of the predefines
1015e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// build prior to including the precompiled header.
1016e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
10176a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor
101889d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor  /// \brief Read preprocessed entities into the preprocessing record.
10196a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor  virtual void ReadPreprocessedEntities();
1020e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor
102189d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor  /// \brief Read the preprocessed entity at the given offset.
10220a480293f726508ad9aed0be39e8c9779e84f2f2Douglas Gregor  virtual PreprocessedEntity *ReadPreprocessedEntityAtOffset(uint64_t Offset);
102389d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor
1024cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// \brief Read the header file information for the given file entry.
1025cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE);
1026cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
10273efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis  void ReadPragmaDiagnosticMappings(Diagnostic &Diag);
1028f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis
1029f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  /// \brief Returns the number of source locations found in the chain.
10300fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  unsigned getTotalNumSLocs() const {
10310fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl    return TotalNumSLocEntries;
10320fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  }
10330fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl
1034f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  /// \brief Returns the number of identifiers found in the chain.
1035f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  unsigned getTotalNumIdentifiers() const {
1036f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl    return static_cast<unsigned>(IdentifiersLoaded.size());
1037f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  }
1038f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl
1039e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of types found in the chain.
104077a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  unsigned getTotalNumTypes() const {
104177a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl    return static_cast<unsigned>(TypesLoaded.size());
104277a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  }
104377a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl
1044e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of declarations found in the chain.
104577a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  unsigned getTotalNumDecls() const {
104677a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl    return static_cast<unsigned>(DeclsLoaded.size());
104777a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  }
104877a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl
1049e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of selectors found in the chain.
1050e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  unsigned getTotalNumSelectors() const {
1051e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl    return static_cast<unsigned>(SelectorsLoaded.size());
1052e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  }
1053e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl
10544c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// \brief Returns the number of preprocessed entities known to the AST
10554c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// reader.
10564c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  unsigned getTotalNumPreprocessedEntities() const {
10574c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    unsigned Result = 0;
10584c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    for (unsigned I = 0, N = Chain.size(); I != N; ++I)
10594c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor      Result += Chain[I]->NumPreallocatedPreprocessingEntities;
10604c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
10614c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    return Result;
10624c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  }
10634c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
106477424bc3794f569816dba52e423b57486a98e5baDouglas Gregor  /// \brief Returns the number of macro definitions found in the chain.
106577424bc3794f569816dba52e423b57486a98e5baDouglas Gregor  unsigned getTotalNumMacroDefinitions() const {
106677424bc3794f569816dba52e423b57486a98e5baDouglas Gregor    return static_cast<unsigned>(MacroDefinitionsLoaded.size());
106777424bc3794f569816dba52e423b57486a98e5baDouglas Gregor  }
106877424bc3794f569816dba52e423b57486a98e5baDouglas Gregor
10697c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor  /// \brief Returns the number of C++ base specifiers found in the chain.
10707c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor  unsigned getTotalNumCXXBaseSpecifiers() const;
10717c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor
1072833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief Reads a TemplateArgumentLocInfo appropriate for the
1073833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// given TemplateArgument kind.
1074833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLocInfo
1075c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  GetTemplateArgumentLocInfo(PerFileData &F, TemplateArgument::ArgKind Kind,
1076833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                             const RecordData &Record, unsigned &Idx);
1077833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
107844f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis  /// \brief Reads a TemplateArgumentLoc.
1079577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl  TemplateArgumentLoc
1080c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  ReadTemplateArgumentLoc(PerFileData &F,
1081577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                          const RecordData &Record, unsigned &Idx);
108244f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis
1083a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall  /// \brief Reads a declarator info from the given record.
1084c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  TypeSourceInfo *GetTypeSourceInfo(PerFileData &F,
1085577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                                    const RecordData &Record, unsigned &Idx);
1086a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
10878871a44ae61cf97ff6fff4c640fadce9ba4cf1b0Argyrios Kyrtzidis  /// \brief Resolve and return the translation unit declaration.
10888871a44ae61cf97ff6fff4c640fadce9ba4cf1b0Argyrios Kyrtzidis  TranslationUnitDecl *GetTranslationUnitDecl();
10898871a44ae61cf97ff6fff4c640fadce9ba4cf1b0Argyrios Kyrtzidis
10902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Resolve a type ID into a type, potentially building a new
10912cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// type.
10928538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  QualType GetType(serialization::TypeID ID);
10932cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
10945d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// \brief Returns the type ID associated with the given type.
10955d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// If the type didn't come from the AST file the ID that is returned is
10965d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// marked as "doesn't exist in AST".
10975d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  serialization::TypeID GetTypeID(QualType T) const;
10985d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis
10995d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// \brief Returns the type index associated with the given type.
11005d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// If the type didn't come from the AST file the index that is returned is
11015d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// marked as "doesn't exist in AST".
11025d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  serialization::TypeIdx GetTypeIdx(QualType T) const;
11035d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis
11042cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Resolve a declaration ID into a declaration, potentially
11052cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// building a new declaration.
11068538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Decl *GetDecl(serialization::DeclID ID);
110776bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual Decl *GetExternalDecl(uint32_t ID);
11082cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
11097c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor  /// \brief Resolve a CXXBaseSpecifiers ID into an offset into the chain
11107c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor  /// of loaded AST files.
11117c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor  uint64_t GetCXXBaseSpecifiersOffset(serialization::CXXBaseSpecifiersID ID);
11127c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor
11137c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor  virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset);
11147c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor
1115250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// \brief Resolve the offset of a statement into a statement.
1116250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  ///
1117250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// This operation will read a new statement from the external
1118250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// source each time it is called, and is meant to be used via a
1119887e2b375fc5e00084ec7bf3dd050c2ca399a6d2Chris Lattner  /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
112076bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual Stmt *GetExternalDeclStmt(uint64_t Offset);
1121250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor
11226367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
11236367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// specified cursor.  Read the abbreviations that are at the top of the block
11246367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// and then leave the cursor pointing into the block.
11256367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
11266367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner
112776bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// \brief Finds all the visible declarations with a given name.
112876bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// The current implementation of this method just loads the entire
112976bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// lookup table as unmaterialized references.
113076bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual DeclContext::lookup_result
113176bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  FindExternalVisibleDeclsByName(const DeclContext *DC,
113276bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall                                 DeclarationName Name);
113376bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall
1134a60786b46eaa4766bb57fb3ca4e0191b3f73e42aArgyrios Kyrtzidis  virtual void MaterializeVisibleDecls(const DeclContext *DC);
1135a60786b46eaa4766bb57fb3ca4e0191b3f73e42aArgyrios Kyrtzidis
11362cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Read all of the declarations lexically stored in a
11372cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declaration context.
11382cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
11392cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \param DC The declaration context whose declarations will be
11402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// read.
11412cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
11422cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \param Decls Vector that will contain the declarations loaded
11432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// from the external source. The caller is responsible for merging
11442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// these declarations with any declarations already stored in the
11452cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declaration context.
11462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
11472cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \returns true if there was an error while reading the
11482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declarations for this declaration context.
1149ba6ffaf21e465c0926d7fc5fa294ea52f8d45fafDouglas Gregor  virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
1150eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis                                        bool (*isKindWeWant)(Decl::Kind),
1151686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                        SmallVectorImpl<Decl*> &Decls);
11522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1153c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief Notify ASTReader that we started deserialization of
115429ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// a decl or type so until FinishedDeserializing is called there may be
115529ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// decls that are initializing. Must be paired with FinishedDeserializing.
115629ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  virtual void StartedDeserializing() { ++NumCurrentElementsDeserializing; }
115729ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis
1158c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief Notify ASTReader that we finished the deserialization of
115929ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// a decl or type. Must be paired with StartedDeserializing.
116029ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  virtual void FinishedDeserializing();
116129ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis
1162fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// \brief Function that will be invoked when we begin parsing a new
1163fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// translation unit involving this external AST source.
1164fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  ///
1165fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// This function will provide all of the external definitions to
1166fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// the ASTConsumer.
1167fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  virtual void StartTranslationUnit(ASTConsumer *Consumer);
1168fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor
11693c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Print some statistics about AST usage.
11702cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  virtual void PrintStats();
11712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1172e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek  /// Return the amount of memory used by memory buffers, breaking down
1173e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek  /// by heap-backed versus mmap'ed memory.
1174e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek  virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const;
1175e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek
1176668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Initialize the semantic source with the Sema instance
1177668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// being used to perform semantic analysis on the abstract syntax
1178668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// tree.
1179668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  virtual void InitializeSema(Sema &S);
1180668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1181ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar  /// \brief Inform the semantic consumer that Sema is no longer available.
1182ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar  virtual void ForgetSema() { SemaObj = 0; }
1183ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar
1184668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the IdentifierInfo for the named identifier.
1185668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  ///
11864d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// This routine builds a new IdentifierInfo for the given identifier. If any
11874d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// declarations with this name are visible from translation unit scope, their
11884d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// declarations will be deserialized and introduced into the declaration
118988a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  /// chain of the identifier.
1190d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd);
1191686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  IdentifierInfo *get(StringRef Name) {
11924d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar    return get(Name.begin(), Name.end());
11934d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  }
1194668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
119595f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  /// \brief Retrieve an iterator into the set of all identifiers
119695f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  /// in all loaded AST files.
119795f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  virtual IdentifierIterator *getIdentifiers() const;
119895f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor
1199f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// \brief Load the contents of the global method pool for a given
1200f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// selector.
1201f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  ///
1202f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// \returns a pair of Objective-C methods lists containing the
1203f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// instance and factory methods, respectively, with this selector.
12041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual std::pair<ObjCMethodList, ObjCMethodList>
1205f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor    ReadMethodPool(Selector Sel);
1206f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor
1207d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  /// \brief Load the set of namespaces that are known to the external source,
1208d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  /// which will be used during typo correction.
1209d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  virtual void ReadKnownNamespaces(
1210686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                           SmallVectorImpl<NamespaceDecl *> &Namespaces);
1211d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor
1212e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Load a selector from disk, registering its ID if it exists.
1213e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  void LoadSelector(Selector Sel);
1214e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl
12152b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
12161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void SetGloballyVisibleDecls(IdentifierInfo *II,
1217686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                               const SmallVectorImpl<uint32_t> &DeclIDs,
1218d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor                               bool Nonrecursive = false);
12191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12200a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor  /// \brief Report a diagnostic.
12210a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor  DiagnosticBuilder Diag(unsigned DiagID);
12220a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor
1223e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor  /// \brief Report a diagnostic.
1224e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
1225e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor
12267356a31327be9b3c3434a0c88746028980da5684Chris Lattner  IdentifierInfo *DecodeIdentifierInfo(unsigned Idx);
12271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12287356a31327be9b3c3434a0c88746028980da5684Chris Lattner  IdentifierInfo *GetIdentifierInfo(const RecordData &Record, unsigned &Idx) {
12297356a31327be9b3c3434a0c88746028980da5684Chris Lattner    return DecodeIdentifierInfo(Record[Idx++]);
12307356a31327be9b3c3434a0c88746028980da5684Chris Lattner  }
12311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12328c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  virtual IdentifierInfo *GetIdentifier(unsigned ID) {
12338c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor    return DecodeIdentifierInfo(ID);
12348c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  }
12358c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor
12367f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// \brief Read the source location entry with index ID.
1237f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  virtual bool ReadSLocEntry(int ID);
12387f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor
123990cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff  Selector DecodeSelector(unsigned Idx);
12401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
124176bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual Selector GetExternalSelector(uint32_t ID);
124276bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  uint32_t GetNumExternalSelectors();
1243719770dcfcb3987e8a2377dcca97955301445eb5Douglas Gregor
124490cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff  Selector GetSelector(const RecordData &Record, unsigned &Idx) {
124590cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff    return DecodeSelector(Record[Idx++]);
124690cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff  }
12476ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
12486ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a declaration name.
12492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  DeclarationName ReadDeclarationName(const RecordData &Record, unsigned &Idx);
12504045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  void ReadDeclarationNameLoc(PerFileData &F,
12514045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                              DeclarationNameLoc &DNLoc, DeclarationName Name,
12524045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                              const RecordData &Record, unsigned &Idx);
12534045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  void ReadDeclarationNameInfo(PerFileData &F, DeclarationNameInfo &NameInfo,
12544045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                               const RecordData &Record, unsigned &Idx);
12554045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
12564045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  void ReadQualifierInfo(PerFileData &F, QualifierInfo &Info,
12574045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                         const RecordData &Record, unsigned &Idx);
12580a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor
12596ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  NestedNameSpecifier *ReadNestedNameSpecifier(const RecordData &Record,
12606ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner                                               unsigned &Idx);
12616ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
1262dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor  NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(PerFileData &F,
1263dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor                                                    const RecordData &Record,
1264dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor                                                    unsigned &Idx);
1265dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor
12668731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// \brief Read a template name.
12671aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  TemplateName ReadTemplateName(PerFileData &F, const RecordData &Record,
12681aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor                                unsigned &Idx);
12698731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis
12708731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// \brief Read a template argument.
1271c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  TemplateArgument ReadTemplateArgument(PerFileData &F,
1272577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                                        const RecordData &Record,unsigned &Idx);
1273dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis
1274dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  /// \brief Read a template parameter list.
1275c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  TemplateParameterList *ReadTemplateParameterList(PerFileData &F,
1276c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                                                   const RecordData &Record,
1277dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis                                                   unsigned &Idx);
1278dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis
1279dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  /// \brief Read a template argument array.
1280dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  void
1281686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs,
1282c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                           PerFileData &F, const RecordData &Record,
1283c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                           unsigned &Idx);
12848731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis
128537ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis  /// \brief Read a UnresolvedSet structure.
128637ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis  void ReadUnresolvedSet(UnresolvedSetImpl &Set,
128737ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis                         const RecordData &Record, unsigned &Idx);
128837ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis
12890745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis  /// \brief Read a C++ base specifier.
1290c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  CXXBaseSpecifier ReadCXXBaseSpecifier(PerFileData &F,
12915606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky                                        const RecordData &Record,unsigned &Idx);
12920745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis
1293cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  /// \brief Read a CXXCtorInitializer array.
1294cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  std::pair<CXXCtorInitializer **, unsigned>
1295cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  ReadCXXCtorInitializers(PerFileData &F, const RecordData &Record,
1296cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt                          unsigned &Idx);
12978e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis
1298c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  /// \brief Read a source location from raw form.
1299c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  SourceLocation ReadSourceLocation(PerFileData &Module, unsigned Raw) {
1300f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    unsigned Flag = Raw & (1U << 31);
1301f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    unsigned Offset = Raw & ~(1U << 31);
1302f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    assert(Module.SLocRemap.find(Offset) != Module.SLocRemap.end() &&
1303f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor           "Cannot find offset to remap.");
1304f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    int Remap = Module.SLocRemap.find(Offset)->second;
1305f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    Offset += Remap;
1306f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    assert((Offset & (1U << 31)) == 0 &&
1307f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor           "Bad offset in reading source location");
1308f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    return SourceLocation::getFromRawEncoding(Offset | Flag);
1309c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  }
1310c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl
13116ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a source location.
1312c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  SourceLocation ReadSourceLocation(PerFileData &Module,
1313c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                                    const RecordData &Record, unsigned& Idx) {
1314c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    return ReadSourceLocation(Module, Record[Idx++]);
13156ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  }
13166ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
13176ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a source range.
1318c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  SourceRange ReadSourceRange(PerFileData &F,
1319c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                              const RecordData &Record, unsigned& Idx);
13206ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
13210a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  /// \brief Read an integral value
13220a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
13230a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor
13240a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  /// \brief Read a signed integral value
13250a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
13263a2f7e42514ddbec983c61826ce85d3071e23e8eDouglas Gregor
132717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Read a floating-point value
132817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  llvm::APFloat ReadAPFloat(const RecordData &Record, unsigned &Idx);
132917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
133068a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor  // \brief Read a string
133168a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor  std::string ReadString(const RecordData &Record, unsigned &Idx);
133268a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor
13330a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  /// \brief Read a version tuple.
13340a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
13350a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor
1336d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  CXXTemporary *ReadCXXTemporary(const RecordData &Record, unsigned &Idx);
1337d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner
133868a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor  /// \brief Reads attributes from the current stream position.
13394eb9fc0449ddbd5239ddc3ae6b6e52880f47dcf7Argyrios Kyrtzidis  void ReadAttributes(PerFileData &F, AttrVec &Attrs,
13404eb9fc0449ddbd5239ddc3ae6b6e52880f47dcf7Argyrios Kyrtzidis                      const RecordData &Record, unsigned &Idx);
134168a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor
1342919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads a statement.
1343c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  Stmt *ReadStmt(PerFileData &F);
13440b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
1345919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads an expression.
1346c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  Expr *ReadExpr(PerFileData &F);
1347c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor
1348d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  /// \brief Reads a sub-statement operand during statement reading.
1349d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  Stmt *ReadSubStmt() {
1350d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    assert(ReadingKind == Read_Stmt &&
1351d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis           "Should be called only during statement reading!");
1352d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    // Subexpressions are stored from last to first, so the next Stmt we need
1353d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    // is at the back of the stack.
1354d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    assert(!StmtStack.empty() && "Read too many sub statements!");
1355d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    return StmtStack.pop_back_val();
1356d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  }
1357d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis
1358d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  /// \brief Reads a sub-expression operand during statement reading.
1359d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  Expr *ReadSubExpr();
1360d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis
136137e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor  /// \brief Reads the macro record located at the given offset.
136289d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor  PreprocessedEntity *ReadMacroRecord(PerFileData &F, uint64_t Offset);
136337e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor
13644800a5c79023271408af49797e09be32aca93232Douglas Gregor  /// \brief Reads the preprocessed entity located at the current stream
13654800a5c79023271408af49797e09be32aca93232Douglas Gregor  /// position.
13664800a5c79023271408af49797e09be32aca93232Douglas Gregor  PreprocessedEntity *LoadPreprocessedEntity(PerFileData &F);
13674800a5c79023271408af49797e09be32aca93232Douglas Gregor
1368295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// \brief Note that the identifier is a macro whose record will be loaded
1369295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// from the given AST file at the given (file-local) offset.
1370295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  void SetIdentifierIsMacro(IdentifierInfo *II, PerFileData &F,
1371295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor                            uint64_t Offset);
1372295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor
137388a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  /// \brief Read the set of macros defined by this external macro source.
137488a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  virtual void ReadDefinedMacros();
137588a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor
1376295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// \brief Read the macro definition for this identifier.
1377295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  virtual void LoadMacroDefinition(IdentifierInfo *II);
1378295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor
1379295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// \brief Read the macro definition corresponding to this iterator
1380295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// into the unread macro record offsets table.
1381295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  void LoadMacroDefinition(
1382295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor                     llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos);
1383295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor
13846a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor  /// \brief Retrieve the macro definition with the given ID.
1385f73c93fea0d4b447585bc7459499ba6b822e045cSebastian Redl  MacroDefinition *getMacroDefinition(serialization::MacroID ID);
1386ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl
13873c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Retrieve the AST context that this AST reader supplements.
1388d1d64a027554b635d644957ef071ec04ea1f7063Chris Lattner  ASTContext *getContext() { return Context; }
1389025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
13906cfc1a8b7582b8433b61222502effb018c534393Douglas Gregor  // \brief Contains declarations that were loaded before we have
13916cfc1a8b7582b8433b61222502effb018c534393Douglas Gregor  // access to a Sema object.
1392686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<NamedDecl *, 16> PreloadedDecls;
1393668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1394668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the semantic analysis object used to analyze the
1395668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// translation unit in which the precompiled header is being
1396668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// imported.
1397668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  Sema *getSema() { return SemaObj; }
1398668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1399668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the identifier table associated with the
1400668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// preprocessor.
1401668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  IdentifierTable &getIdentifierTable();
1402668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1403025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Record that the given ID maps to the given switch-case
1404025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// statement.
1405025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
1406025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1407025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Retrieve the switch-case statement with the given ID.
1408025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SwitchCase *getSwitchCaseWithID(unsigned ID);
14091de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
1410e09a275444576deb2c8d9e2255554242f65d7c00Argyrios Kyrtzidis  void ClearSwitchCaseIDs();
14112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor};
14122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
141302602be3ccc3b29da5b91d2502c3419404992409Chris Lattner/// \brief Helper class that saves the current stream position and
141402602be3ccc3b29da5b91d2502c3419404992409Chris Lattner/// then restores it when destroyed.
141502602be3ccc3b29da5b91d2502c3419404992409Chris Lattnerstruct SavedStreamPosition {
141602602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
141702602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { }
14181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
141902602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  ~SavedStreamPosition() {
142002602be3ccc3b29da5b91d2502c3419404992409Chris Lattner    Cursor.JumpToBit(Offset);
142102602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  }
14221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
142302602be3ccc3b29da5b91d2502c3419404992409Chris Lattnerprivate:
142402602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  llvm::BitstreamCursor &Cursor;
142502602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  uint64_t Offset;
142602602be3ccc3b29da5b91d2502c3419404992409Chris Lattner};
14271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1428d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenekinline void PCHValidator::Error(const char *Msg) {
1429d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  Reader.Error(Msg);
1430d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek}
1431d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek
14322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} // end namespace clang
14332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
14342cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#endif
1435