ASTReader.h revision 27ffa6caf965ef20fdef5ae23b81cdc3d05e7afb
16ab7cd853e9c15cf986a8a7c3db1f8d20e275409Sebastian Redl//===--- ASTReader.h - AST File Reader --------------------------*- C++ -*-===//
22cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//
32cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//                     The LLVM Compiler Infrastructure
42cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//
52cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// This file is distributed under the University of Illinois Open Source
62cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// License. See LICENSE.TXT for details.
72cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//
82cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===//
92cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//
10c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl//  This file defines the ASTReader class, which reads AST files.
112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//
122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===//
138b12273c86ede439edf52d35b170fd32b2ed49d4Sebastian Redl
14f29f0a28c4d9599b389bbb6d186e14af753dc5a3Sebastian Redl#ifndef LLVM_CLANG_FRONTEND_AST_READER_H
15f29f0a28c4d9599b389bbb6d186e14af753dc5a3Sebastian Redl#define LLVM_CLANG_FRONTEND_AST_READER_H
162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1705a07605322dfef2b017781042043a261c5a89cdSebastian Redl#include "clang/Serialization/ASTBitCodes.h"
18f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor#include "clang/Serialization/ContinuousRangeMap.h"
1998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor#include "clang/Serialization/Module.h"
2098339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor#include "clang/Serialization/ModuleManager.h"
21668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor#include "clang/Sema/ExternalSemaSource.h"
22c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl#include "clang/AST/DeclarationName.h"
23f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor#include "clang/AST/DeclObjC.h"
24833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall#include "clang/AST/TemplateBase.h"
2588a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor#include "clang/Lex/ExternalPreprocessorSource.h"
26cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor#include "clang/Lex/HeaderSearch.h"
27a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor#include "clang/Lex/PPMutationListener.h"
286a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor#include "clang/Lex/PreprocessingRecord.h"
290a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor#include "clang/Basic/Diagnostic.h"
301afb661bc5444462a246cefa0effa61ef25fab29Jonathan D. Turner#include "clang/Basic/FileManager.h"
311afb661bc5444462a246cefa0effa61ef25fab29Jonathan D. Turner#include "clang/Basic/FileSystemOptions.h"
32668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor#include "clang/Basic/IdentifierTable.h"
337f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor#include "clang/Basic/SourceManager.h"
3417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor#include "llvm/ADT/APFloat.h"
350a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor#include "llvm/ADT/APInt.h"
360a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor#include "llvm/ADT/APSInt.h"
37ce12d2f8863588d408897602089d17c4d3c3d0e5Douglas Gregor#include "llvm/ADT/MapVector.h"
382cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/ADT/OwningPtr.h"
390f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor#include "llvm/ADT/SmallPtrSet.h"
400f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor#include "llvm/ADT/SmallSet.h"
412cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/ADT/SmallVector.h"
42dc3c0d20375bda7775b2fade05b20e315798b9feDaniel Dunbar#include "llvm/ADT/StringRef.h"
43e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis#include "llvm/ADT/DenseSet.h"
442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/Bitcode/BitstreamReader.h"
4503013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer#include "llvm/Support/DataTypes.h"
46d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor#include <deque>
47025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor#include <map>
482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <string>
492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <utility>
502cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <vector>
512cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace llvm {
532cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  class MemoryBuffer;
542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
552cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
562cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace clang {
572cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
587d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregorclass AddrLabelExpr;
590af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregorclass ASTConsumer;
602cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass ASTContext;
6195f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregorclass ASTIdentifierIterator;
62f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregorclass ASTUnit; // FIXME: Layering violation and egregious hack.
6368a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregorclass Attr;
642cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass Decl;
652cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass DeclContext;
666ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattnerclass NestedNameSpecifier;
676ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattnerclass CXXBaseSpecifier;
68ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Huntclass CXXConstructorDecl;
69cbb67480094b3bcb5b715acd827cbad55e2a204cSean Huntclass CXXCtorInitializer;
701de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregorclass GotoStmt;
716a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregorclass MacroDefinition;
72668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregorclass NamedDecl;
7356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr;
7414f79002e58556798e86168c63e48d533287eda5Douglas Gregorclass Preprocessor;
75668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregorclass Sema;
76025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorclass SwitchCase;
77c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redlclass ASTDeserializationListener;
78f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregorclass ASTWriter;
79c43b54cbc10654ed59de797898042e1a05265246Sebastian Redlclass ASTReader;
80d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redlclass ASTDeclReader;
81c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redlclass ASTStmtReader;
82c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redlclass TypeLocReader;
83eb19485625c7529ffa644e10829533157a8e8d4fDaniel Dunbarstruct HeaderFileInfo;
840a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregorclass VersionTuple;
8557016dda61498294120b1a881d9e6606337b29d9Douglas Gregorclass TargetOptions;
8611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis
877e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redlstruct PCHPredefinesBlock {
887e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// \brief The file ID for this predefines buffer in a PCH file.
897e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  FileID BufferID;
907e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl
917e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// \brief This predefines buffer in a PCH file.
92686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef Data;
937e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl};
94686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<PCHPredefinesBlock, 2> PCHPredefinesBlocks;
957e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl
96c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// \brief Abstract interface for callback invocations by the ASTReader.
9711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis///
98c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// While reading an AST file, the ASTReader will call the methods of the
9911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis/// listener to pass on specific information. Some of the listener methods can
100c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// return true to indicate to the ASTReader that the information (and
101571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl/// consequently the AST file) is invalid.
102571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redlclass ASTReaderListener {
10311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidispublic:
104571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  virtual ~ASTReaderListener();
1051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives the language options.
10711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
10811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \returns true to indicate the options are invalid or false otherwise.
10927ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor  virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
11038295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor                                   bool Complain) {
11111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
11211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
1131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11457016dda61498294120b1a881d9e6606337b29d9Douglas Gregor  /// \brief Receives the target options.
11511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
11657016dda61498294120b1a881d9e6606337b29d9Douglas Gregor  /// \returns true to indicate the target options are invalid, or false
11757016dda61498294120b1a881d9e6606337b29d9Douglas Gregor  /// otherwise.
11827ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor  virtual bool ReadTargetOptions(const TargetOptions &TargetOpts,
11938295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor                                 bool Complain) {
12011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
12111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives the contents of the predefines buffer.
12411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
12530c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl  /// \param Buffers Information about the predefines buffers.
12611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
1273c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param OriginalFileName The original file name for the AST file, which
1283c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// will appear as an entry in the predefines buffer.
1297b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar  ///
13011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \param SuggestedPredefines If necessary, additional definitions are added
13111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// here.
13211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
13338295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  /// \param Complain Whether to complain about non-matching predefines buffers.
13438295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  ///
13511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \returns true to indicate the predefines are invalid or false otherwise.
1367e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
137686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                    StringRef OriginalFileName,
138277a6e752512cff286190d35cb353ce717e86b18Nick Lewycky                                    std::string &SuggestedPredefines,
13938295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor                                    FileManager &FileMgr,
14038295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor                                    bool Complain) {
14111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
14211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
1431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives a HeaderFileInfo entry.
14512fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor  virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID) {}
1461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives __COUNTER__ value.
14862288edde26ff4af9fc079c979a0e1bdc577ce9dArgyrios Kyrtzidis  virtual void ReadCounter(const serialization::ModuleFile &M,
14962288edde26ff4af9fc079c979a0e1bdc577ce9dArgyrios Kyrtzidis                           unsigned Value) {}
15011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis};
15111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis
152571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl/// \brief ASTReaderListener implementation to validate the information of
15311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis/// the PCH file against an initialized Preprocessor.
154571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redlclass PCHValidator : public ASTReaderListener {
15511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  Preprocessor &PP;
156c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader &Reader;
1571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  unsigned NumHeaderInfos;
1591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidispublic:
161c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  PCHValidator(Preprocessor &PP, ASTReader &Reader)
16211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    : PP(PP), Reader(Reader), NumHeaderInfos(0) {}
1631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16427ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor  virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
16538295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor                                   bool Complain);
16627ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor  virtual bool ReadTargetOptions(const TargetOptions &TargetOpts,
16738295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor                                 bool Complain);
1687e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
169686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                    StringRef OriginalFileName,
170277a6e752512cff286190d35cb353ce717e86b18Nick Lewycky                                    std::string &SuggestedPredefines,
17138295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor                                    FileManager &FileMgr,
17238295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor                                    bool Complain);
17312fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor  virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID);
17462288edde26ff4af9fc079c979a0e1bdc577ce9dArgyrios Kyrtzidis  virtual void ReadCounter(const serialization::ModuleFile &M, unsigned Value);
175d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek
176d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenekprivate:
177d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  void Error(const char *Msg);
17811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis};
1792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
180ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikienamespace serialization {
1815d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner
1823d15ab8d0822637ff5e39594c4f34172241cad2eDouglas Gregorclass ReadMethodPoolVisitor;
183ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18498339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregornamespace reader {
18598339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor  class ASTIdentifierLookupTrait;
186b1758c662524e18d65d260188fdcbbdee6a9316bBenjamin Kramer  /// \brief The on-disk hash table used for the DeclContext's Name lookup table.
187b1758c662524e18d65d260188fdcbbdee6a9316bBenjamin Kramer  typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait>
188b1758c662524e18d65d260188fdcbbdee6a9316bBenjamin Kramer    ASTDeclContextNameLookupTable;
18998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor}
190ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
19172a9ae18553bf8b6bdad84d2c54f73741a47e275Douglas Gregor} // end namespace serialization
192ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
193c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// \brief Reads an AST files chain containing the contents of a translation
194c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// unit.
1952cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor///
196c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// The ASTReader class reads bitstreams (produced by the ASTWriter
1972cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// class) containing the serialized representation of a given
1982cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// abstract syntax tree and its supporting data structures. An
199c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// instance of the ASTReader can be attached to an ASTContext object,
200c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// which will provide access to the contents of the AST files.
2012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor///
202c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// The AST reader provides lazy de-serialization of declarations, as
2032cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// required when traversing the AST. Only those AST nodes that are
2042cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// actually required will be de-serialized.
205c43b54cbc10654ed59de797898042e1a05265246Sebastian Redlclass ASTReader
20688a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  : public ExternalPreprocessorSource,
2076a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor    public ExternalPreprocessingRecordSource,
208cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    public ExternalHeaderFileInfoSource,
20988a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor    public ExternalSemaSource,
2108c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor    public IdentifierInfoLookup,
2117f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor    public ExternalIdentifierLookup,
212ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    public ExternalSLocEntrySource
213cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor{
214e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregorpublic:
215260611a32535c851237926bfcf78869b13c07d5bJohn McCall  typedef SmallVector<uint64_t, 64> RecordData;
216260611a32535c851237926bfcf78869b13c07d5bJohn McCall
2174825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor  /// \brief The result of reading the control block of an AST file, which
2184825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor  /// can fail for various reasons.
2194825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor  enum ASTReadResult {
2204825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    /// \brief The control block was read successfully. Aside from failures,
2214825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    /// the AST file is safe to read into the current context.
2224825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    Success,
2234825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    /// \brief The AST file itself appears corrupted.
2244825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    Failure,
2254825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    /// \brief The AST file is out-of-date relative to its input files,
2264825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    /// and needs to be regenerated.
2274825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    OutOfDate,
2284825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    /// \brief The AST file was written by a different version of Clang.
2294825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    VersionMismatch,
2304825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    /// \brief The AST file was writtten with a different language/target
2314825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    /// configuration.
2324825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    ConfigurationMismatch,
2334825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    /// \brief The AST file has errors.
2344825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor    HadErrors
2354825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor  };
2364825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor
2371d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl  /// \brief Types of AST files.
238d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  friend class PCHValidator;
239d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl  friend class ASTDeclReader;
240c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  friend class ASTStmtReader;
24195f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  friend class ASTIdentifierIterator;
24298339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor  friend class serialization::reader::ASTIdentifierLookupTrait;
243c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  friend class TypeLocReader;
244f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  friend class ASTWriter;
245f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  friend class ASTUnit; // ASTUnit needs to remap source locations.
2463d15ab8d0822637ff5e39594c4f34172241cad2eDouglas Gregor  friend class serialization::ReadMethodPoolVisitor;
247ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2481a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef serialization::ModuleFile ModuleFile;
24972a9ae18553bf8b6bdad84d2c54f73741a47e275Douglas Gregor  typedef serialization::ModuleKind ModuleKind;
2505d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  typedef serialization::ModuleManager ModuleManager;
251ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2525d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  typedef ModuleManager::ModuleIterator ModuleIterator;
2535d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  typedef ModuleManager::ModuleConstIterator ModuleConstIterator;
2545d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  typedef ModuleManager::ModuleReverseIterator ModuleReverseIterator;
2555d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner
256e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregorprivate:
257c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief The receiver of some callbacks invoked by ASTReader.
2586f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith  OwningPtr<ASTReaderListener> Listener;
2591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26030c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl  /// \brief The receiver of deserialization events.
261571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  ASTDeserializationListener *DeserializationListener;
26230c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl
26311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  SourceManager &SourceMgr;
26411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  FileManager &FileMgr;
265d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  DiagnosticsEngine &Diags;
266ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
267668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief The semantic analysis object that will be processing the
2683c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// AST files and the translation unit that uses it.
269668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  Sema *SemaObj;
270668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
27114f79002e58556798e86168c63e48d533287eda5Douglas Gregor  /// \brief The preprocessor that will be loading the source file.
272712f2fcb70ae2eb0cb684d565e7d2cb76881006bDouglas Gregor  Preprocessor &PP;
27314f79002e58556798e86168c63e48d533287eda5Douglas Gregor
2743c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The AST context into which we'll read the AST files.
275359427794704666ff7a5a933ace11c5256fa3af7Douglas Gregor  ASTContext &Context;
276ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2770af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor  /// \brief The AST consumer.
2780af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor  ASTConsumer *Consumer;
2790af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor
2805d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  /// \brief The module manager which manages modules and their dependencies
2815d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  ModuleManager ModuleMgr;
2829137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
2838f1231b70c2b1f6fe0cee097b447487b26810301Douglas Gregor  /// \brief A map of global bit offsets to the module that stores entities
2848f1231b70c2b1f6fe0cee097b447487b26810301Douglas Gregor  /// at those bit offsets.
2851a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap;
2868f1231b70c2b1f6fe0cee097b447487b26810301Douglas Gregor
287f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// \brief A map of negated SLocEntryIDs to the modules containing them.
2881a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap;
2894ee5a6f9bd82ab3c1a4bdacc0caefe7d5f8bd37aSebastian Redl
2901a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocOffsetMapType;
291ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
292a68c4aff8cd3aada697ad36dc6582d0e09b4b0d2Argyrios Kyrtzidis  /// \brief A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
293a68c4aff8cd3aada697ad36dc6582d0e09b4b0d2Argyrios Kyrtzidis  /// SourceLocation offsets to the modules containing them.
2942dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  GlobalSLocOffsetMapType GlobalSLocOffsetMap;
295ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2963c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Types that have already been loaded from the chain.
2971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
2981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// When the pointer at index I is non-NULL, the type with
2993c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// ID = (I + 1) << FastQual::Width has already been loaded
3000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::vector<QualType> TypesLoaded;
3012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
3021a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>
303e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner    GlobalTypeMapType;
304e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner
305e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  /// \brief Mapping from global type IDs to the module in which the
306e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  /// type resides along with the offset that should be added to the
307e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  /// global type ID to produce a local ID.
308e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  GlobalTypeMapType GlobalTypeMap;
309e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner
3103c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Declarations that have already been loaded from the chain.
3112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
3128f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  /// When the pointer at index I is non-NULL, the declaration with ID
3138f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  /// = I + 1 has already been loaded.
3148f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  std::vector<Decl *> DeclsLoaded;
3152cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
3161a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>
31796e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor    GlobalDeclMapType;
318ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
31996e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor  /// \brief Mapping from global declaration IDs to the module in which the
3209827a8049a793f23c62ade8f24f0c66c2dbf6741Douglas Gregor  /// declaration resides.
32196e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor  GlobalDeclMapType GlobalDeclMap;
322ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3231a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef std::pair<ModuleFile *, uint64_t> FileOffset;
324686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<FileOffset, 2> FileOffsetsTy;
3257b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy>
3267b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis      DeclUpdateOffsetsMap;
327ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3287b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  /// \brief Declarations that have modifications residing in a later file
3297b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  /// in the chain.
3307b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  DeclUpdateOffsetsMap DeclUpdateOffsets;
3317b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis
332ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis  struct ReplacedDeclInfo {
3331a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    ModuleFile *Mod;
334ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis    uint64_t Offset;
335ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis    unsigned RawLoc;
336ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis
337ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis    ReplacedDeclInfo() : Mod(0), Offset(0), RawLoc(0) {}
3381a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    ReplacedDeclInfo(ModuleFile *Mod, uint64_t Offset, unsigned RawLoc)
339ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis      : Mod(Mod), Offset(Offset), RawLoc(RawLoc) {}
340ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis  };
341ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis
342ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis  typedef llvm::DenseMap<serialization::DeclID, ReplacedDeclInfo>
3430b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl      DeclReplacementMap;
3440b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl  /// \brief Declarations that have been replaced in a later file in the chain.
3450b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl  DeclReplacementMap ReplacedDecls;
3460b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl
3479d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis  struct FileDeclsInfo {
3481a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    ModuleFile *Mod;
3499d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis    ArrayRef<serialization::LocalDeclID> Decls;
3509d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis
3519d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis    FileDeclsInfo() : Mod(0) {}
3521a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
3539d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis      : Mod(Mod), Decls(Decls) {}
3549d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis  };
3559d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis
35610f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis  /// \brief Map from a FileID to the file-level declarations that it contains.
3579d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis  llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
35810f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis
359e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // Updates for visible decls can occur for other contexts than just the
360e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // TU, and when we read those update records, the actual context will not
361e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // be available yet (unless it's the TU), so have this pending map using the
362e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // ID as a key. It will be realized when the context is actually loaded.
363b1758c662524e18d65d260188fdcbbdee6a9316bBenjamin Kramer  typedef
364b1758c662524e18d65d260188fdcbbdee6a9316bBenjamin Kramer    SmallVector<std::pair<serialization::reader::ASTDeclContextNameLookupTable *,
365b1758c662524e18d65d260188fdcbbdee6a9316bBenjamin Kramer                          ModuleFile*>, 1> DeclContextVisibleUpdates;
366e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
367e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl      DeclContextVisibleUpdatesPending;
3682cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
369e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  /// \brief Updates to the visible declarations of declaration contexts that
370e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  /// haven't been loaded yet.
371e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  DeclContextVisibleUpdatesPending PendingVisibleUpdates;
3722e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
373fc529f7fcafe7da0b8a32621e13685891e8ce52aDouglas Gregor  /// \brief The set of C++ or Objective-C classes that have forward
374fc529f7fcafe7da0b8a32621e13685891e8ce52aDouglas Gregor  /// declarations that have not yet been linked to their definitions.
375fc529f7fcafe7da0b8a32621e13685891e8ce52aDouglas Gregor  llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
3765456b0fe40714a78cd0ba7c1a5b7dc34eda385afDouglas Gregor
377ce12d2f8863588d408897602089d17c4d3c3d0e5Douglas Gregor  typedef llvm::MapVector<Decl *, uint64_t,
378ce12d2f8863588d408897602089d17c4d3c3d0e5Douglas Gregor                          llvm::SmallDenseMap<Decl *, unsigned, 4>,
379ce12d2f8863588d408897602089d17c4d3c3d0e5Douglas Gregor                          llvm::SmallVector<std::pair<Decl *, uint64_t>, 4> >
380ce12d2f8863588d408897602089d17c4d3c3d0e5Douglas Gregor    PendingBodiesMap;
381ce12d2f8863588d408897602089d17c4d3c3d0e5Douglas Gregor
3825456b0fe40714a78cd0ba7c1a5b7dc34eda385afDouglas Gregor  /// \brief Functions or methods that have bodies that will be attached.
383ce12d2f8863588d408897602089d17c4d3c3d0e5Douglas Gregor  PendingBodiesMap PendingBodies;
3845456b0fe40714a78cd0ba7c1a5b7dc34eda385afDouglas Gregor
385681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl  /// \brief Read the records that describe the contents of declcontexts.
3861a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  bool ReadDeclContextStorage(ModuleFile &M,
3870d95f77ba180aee35b74f3bf9f8543477f3af543Douglas Gregor                              llvm::BitstreamCursor &Cursor,
388681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl                              const std::pair<uint64_t, uint64_t> &Offsets,
3890d95f77ba180aee35b74f3bf9f8543477f3af543Douglas Gregor                              serialization::DeclContextInfo &Info);
390681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl
3912b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// \brief A vector containing identifiers that have already been
3922b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// loaded.
3932b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  ///
3942b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// If the pointer at index I is non-NULL, then it refers to the
3952b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// IdentifierInfo for the identifier with ID=I+1 that has already
3962b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// been loaded.
3972b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  std::vector<IdentifierInfo *> IdentifiersLoaded;
398afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor
3991a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>
40067268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor    GlobalIdentifierMapType;
401ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
402a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// \brief Mapping from global identifier IDs to the module in which the
40367268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  /// identifier resides along with the offset that should be added to the
40467268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  /// global identifier ID to produce a local ID.
40567268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  GlobalIdentifierMapType GlobalIdentifierMap;
40667268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor
407a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// \brief A vector containing macros that have already been
408a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// loaded.
409a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  ///
410a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// If the pointer at index I is non-NULL, then it refers to the
411a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// MacroInfo for the identifier with ID=I+1 that has already
412a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// been loaded.
413a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  std::vector<MacroInfo *> MacrosLoaded;
414a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor
415a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  typedef ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>
416a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor    GlobalMacroMapType;
417a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor
418a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// \brief Mapping from global macro IDs to the module in which the
419a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// macro resides along with the offset that should be added to the
420a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// global macro ID to produce a local ID.
421a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  GlobalMacroMapType GlobalMacroMap;
422a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor
42354c8a40ed658676b1f3f983728feae488c501477Douglas Gregor  typedef llvm::DenseMap<serialization::MacroID,
42454c8a40ed658676b1f3f983728feae488c501477Douglas Gregor            llvm::SmallVector<std::pair<serialization::SubmoduleID,
42554c8a40ed658676b1f3f983728feae488c501477Douglas Gregor                                        MacroUpdate>, 1> >
42654c8a40ed658676b1f3f983728feae488c501477Douglas Gregor    MacroUpdatesMap;
427a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor
428a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// \brief Mapping from (global) macro IDs to the set of updates to be
429a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// performed to the corresponding macro.
430a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  MacroUpdatesMap MacroUpdates;
431a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor
43226ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief A vector containing submodules that have already been loaded.
43326ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  ///
43426ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// This vector is indexed by the Submodule ID (-1). NULL submodule entries
43526ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// indicate that the particular submodule ID has not yet been loaded.
43626ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  SmallVector<Module *, 2> SubmodulesLoaded;
43726ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
43826ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  typedef ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>
43926ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor    GlobalSubmoduleMapType;
44026ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
44126ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief Mapping from global submodule IDs to the module file in which the
44226ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// submodule resides along with the offset that should be added to the
44326ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// global submodule ID to produce a local ID.
44426ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  GlobalSubmoduleMapType GlobalSubmoduleMap;
44526ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
4466c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor  /// \brief An entity that has been hidden.
4476c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor  class HiddenName {
44854c8a40ed658676b1f3f983728feae488c501477Douglas Gregor  public:
44954c8a40ed658676b1f3f983728feae488c501477Douglas Gregor    enum NameKind {
45054c8a40ed658676b1f3f983728feae488c501477Douglas Gregor      Declaration,
45154c8a40ed658676b1f3f983728feae488c501477Douglas Gregor      MacroVisibility,
45254c8a40ed658676b1f3f983728feae488c501477Douglas Gregor      MacroUndef
45354c8a40ed658676b1f3f983728feae488c501477Douglas Gregor    } Kind;
45454c8a40ed658676b1f3f983728feae488c501477Douglas Gregor
45554c8a40ed658676b1f3f983728feae488c501477Douglas Gregor  private:
45654c8a40ed658676b1f3f983728feae488c501477Douglas Gregor    unsigned Loc;
45754c8a40ed658676b1f3f983728feae488c501477Douglas Gregor
45854c8a40ed658676b1f3f983728feae488c501477Douglas Gregor    union {
45954c8a40ed658676b1f3f983728feae488c501477Douglas Gregor      Decl *D;
46054c8a40ed658676b1f3f983728feae488c501477Douglas Gregor      MacroInfo *MI;
46154c8a40ed658676b1f3f983728feae488c501477Douglas Gregor    };
4626c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor
46354c8a40ed658676b1f3f983728feae488c501477Douglas Gregor    IdentifierInfo *Id;
4646c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor
4656c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor  public:
46654c8a40ed658676b1f3f983728feae488c501477Douglas Gregor    HiddenName(Decl *D) : Kind(Declaration), Loc(), D(D), Id() { }
46754c8a40ed658676b1f3f983728feae488c501477Douglas Gregor
4686c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor    HiddenName(IdentifierInfo *II, MacroInfo *MI)
46954c8a40ed658676b1f3f983728feae488c501477Douglas Gregor      : Kind(MacroVisibility), Loc(), MI(MI), Id(II) { }
47054c8a40ed658676b1f3f983728feae488c501477Douglas Gregor
47154c8a40ed658676b1f3f983728feae488c501477Douglas Gregor    HiddenName(IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc)
47254c8a40ed658676b1f3f983728feae488c501477Douglas Gregor      : Kind(MacroUndef), Loc(Loc.getRawEncoding()), MI(MI), Id(II) { }
4736c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor
47454c8a40ed658676b1f3f983728feae488c501477Douglas Gregor    NameKind getKind() const { return Kind; }
4756c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor
4766c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor    Decl *getDecl() const {
47754c8a40ed658676b1f3f983728feae488c501477Douglas Gregor      assert(getKind() == Declaration && "Hidden name is not a declaration");
47854c8a40ed658676b1f3f983728feae488c501477Douglas Gregor      return D;
4796c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor    }
4806c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor
4816c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor    std::pair<IdentifierInfo *, MacroInfo *> getMacro() const {
48254c8a40ed658676b1f3f983728feae488c501477Douglas Gregor      assert((getKind() == MacroUndef || getKind() == MacroVisibility)
48354c8a40ed658676b1f3f983728feae488c501477Douglas Gregor             && "Hidden name is not a macro!");
48454c8a40ed658676b1f3f983728feae488c501477Douglas Gregor      return std::make_pair(Id, MI);
4856c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor    }
48654c8a40ed658676b1f3f983728feae488c501477Douglas Gregor
48754c8a40ed658676b1f3f983728feae488c501477Douglas Gregor    SourceLocation getMacroUndefLoc() const {
48854c8a40ed658676b1f3f983728feae488c501477Douglas Gregor      assert(getKind() == MacroUndef && "Hidden name is not an undef!");
48954c8a40ed658676b1f3f983728feae488c501477Douglas Gregor      return SourceLocation::getFromRawEncoding(Loc);
49054c8a40ed658676b1f3f983728feae488c501477Douglas Gregor    }
49154c8a40ed658676b1f3f983728feae488c501477Douglas Gregor};
4926c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor
493ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// \brief A set of hidden declarations.
4946c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor  typedef llvm::SmallVector<HiddenName, 2>
4951329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor    HiddenNames;
496ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
497ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType;
498ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
499ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// \brief A mapping from each of the hidden submodules to the deserialized
500ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// declarations in that submodule that could be made visible.
501ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  HiddenNamesMapType HiddenNamesMap;
502ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
50355988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor
50455988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  /// \brief A module import or export that hasn't yet been resolved.
50555988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  struct UnresolvedModuleImportExport {
506af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor    /// \brief The file in which this module resides.
507af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor    ModuleFile *File;
508af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor
50955988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    /// \brief The module that is importing or exporting.
51055988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    Module *Mod;
511af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor
512af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor    /// \brief The local ID of the module that is being exported.
51355988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    unsigned ID;
51455988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor
51555988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    /// \brief Whether this is an import (vs. an export).
51655988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    unsigned IsImport : 1;
51755988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor
51855988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    /// \brief Whether this is a wildcard export.
51955988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    unsigned IsWildcard : 1;
520af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor  };
521af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor
52255988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  /// \brief The set of module imports and exports that still need to be
52355988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  /// resolved.
52455988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  llvm::SmallVector<UnresolvedModuleImportExport, 2>
52555988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    UnresolvedModuleImportExports;
526af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor
5271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief A vector containing selectors that have already been loaded.
52883941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  ///
52983941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// This vector is indexed by the Selector ID (-1). NULL selector
53083941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// entries indicate that the particular selector ID has not yet
53183941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// been loaded.
532686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Selector, 16> SelectorsLoaded;
533725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl
5341a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>
53596958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor    GlobalSelectorMapType;
536ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
53796958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  /// \brief Mapping from global selector IDs to the module in which the
53896958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  /// selector resides along with the offset that should be added to the
53996958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  /// global selector ID to produce a local ID.
54096958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  GlobalSelectorMapType GlobalSelectorMap;
54196958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor
5428efca6bb688d32fd7c0d91b504ef3307f97ee66aDouglas Gregor  /// \brief The generation number of the last time we loaded data from the
5438efca6bb688d32fd7c0d91b504ef3307f97ee66aDouglas Gregor  /// global method pool for this selector.
5448efca6bb688d32fd7c0d91b504ef3307f97ee66aDouglas Gregor  llvm::DenseMap<Selector, unsigned> SelectorGeneration;
5458efca6bb688d32fd7c0d91b504ef3307f97ee66aDouglas Gregor
546e9652bf15246d6e08e953b52cdb7812ddb8a43e0Douglas Gregor  typedef llvm::MapVector<IdentifierInfo *,
547e9652bf15246d6e08e953b52cdb7812ddb8a43e0Douglas Gregor                          llvm::SmallVector<serialization::MacroID, 2> >
5486c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor    PendingMacroIDsMap;
5496c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor
5506c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor  /// \brief Mapping from identifiers that have a macro history to the global
5516c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor  /// IDs have not yet been deserialized to the global IDs of those macros.
5526c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor  PendingMacroIDsMap PendingMacroIDs;
5534c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
5541a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<unsigned, ModuleFile *, 4>
5554c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    GlobalPreprocessedEntityMapType;
556ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5574c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// \brief Mapping from global preprocessing entity IDs to the module in
5584c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// which the preprocessed entity resides along with the offset that should be
5594c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// added to the global preprocessing entitiy ID to produce a local ID.
5604c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
561ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
562892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \name CodeGen-relevant special data
563892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief Fields containing data that is relevant to CodeGen.
564892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@{
565892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
566892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all declarations that fulfill the criteria of
567892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// "interesting" decls.
568892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
569892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// This contains the data loaded from all EXTERNAL_DEFINITIONS blocks in the
570892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// chain. The referenced declarations are deserialized and passed to the
571892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// consumer eagerly.
572686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> ExternalDefinitions;
573fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor
574bed28ac1d1463adca3ecf24fca5c30646fa9dbb2Sylvestre Ledru  /// \brief The IDs of all tentative definitions stored in the chain.
575892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
576892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema keeps track of all tentative definitions in a TU because it has to
577892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// complete them and pass them on to CodeGen. Thus, tentative definitions in
578892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// the PCH chain must be eagerly deserialized.
579686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> TentativeDefinitions;
580892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
581892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are
582892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// used.
583892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
584892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// CodeGen has to emit VTables for these records, so they have to be eagerly
585892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// deserialized.
586686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 64> VTableUses;
587892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
588f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// \brief A snapshot of the pending instantiations in the chain.
589f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  ///
590f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// This record tracks the instantiations that Sema has to perform at the
591f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// end of the TU. It consists of a pair of values for every pending
592f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// instantiation where the first value is the ID of the decl and the second
593f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// is the instantiation location.
594f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  SmallVector<uint64_t, 64> PendingInstantiations;
595f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor
596892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@}
597892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
598d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  /// \name DiagnosticsEngine-relevant special data
599892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief Fields containing data that is used for generating diagnostics
600892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@{
601892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
602892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief A snapshot of Sema's unused file-scoped variable tracking, for
603892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// generating warnings.
604686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> UnusedFileScopedDecls;
6054c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor
606ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt  /// \brief A list of all the delegating constructors we've seen, to diagnose
607ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt  /// cycles.
608686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> DelegatingCtorDecls;
609ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6108451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  /// \brief Method selectors used in a @selector expression. Used for
6118451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  /// implementation of -Wselector.
6128451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  SmallVector<uint64_t, 64> ReferencedSelectorsData;
613ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt
614892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief A snapshot of Sema's weak undeclared identifier tracking, for
615892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// generating warnings.
616686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
61714c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor
618892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of type aliases for ext_vectors that exist in the chain.
619892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
620892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
621686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> ExtVectorDecls;
622b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor
623892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@}
624d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis
625892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \name Sema-relevant special data
626892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief Fields containing data that is used for semantic analysis
627892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@{
628892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
629892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all locally scoped external decls in the chain.
630892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
631892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema tracks these to validate that the types are consistent across all
632892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// local external declarations.
633686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> LocallyScopedExternalDecls;
634d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis
635892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all dynamic class declarations in the chain.
636892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
637892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema tracks these because it checks for the key functions being defined
638892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// at the end of the TU, in which case it directs CodeGen to emit the VTable.
639686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> DynamicClasses;
640892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
641892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of the declarations Sema stores directly.
642892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
643892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema tracks a few important decls, such as namespace std, directly.
644686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> SemaDeclRefs;
64576c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis
646e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// \brief The IDs of the types ASTContext stores directly.
647e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  ///
648e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// The AST context tracks a few important types, such as va_list, directly.
649686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> SpecialTypes;
650e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl
65114b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  /// \brief The IDs of CUDA-specific declarations ASTContext stores directly.
65214b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  ///
65314b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  /// The AST context tracks a few important decls, currently cudaConfigureCall,
65414b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  /// directly.
655686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
65614b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne
65784bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne  /// \brief The floating point pragma option settings.
658686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 1> FPPragmaOptions;
65984bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne
66084bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne  /// \brief The OpenCL extension settings.
661686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 1> OpenCLExtensions;
66284bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne
663d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  /// \brief A list of the namespaces we've seen.
664686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> KnownNamespaces;
665d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor
666f6137e4d15cb6bbd10547267babfc699c1945873Douglas Gregor  /// \brief A list of modules that were imported by precompiled headers or
667f6137e4d15cb6bbd10547267babfc699c1945873Douglas Gregor  /// any other non-module AST file.
668f6137e4d15cb6bbd10547267babfc699c1945873Douglas Gregor  SmallVector<serialization::SubmoduleID, 2> ImportedModules;
669892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@}
670892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
6718e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  /// \brief The directory that the PCH we are reading is stored in.
6728e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  std::string CurrentDir;
6738e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis
6741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief The system include root to be used when loading the
675e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// precompiled header.
676832d620b4ae0fc5fe28561b885b4cfc65cf5c9abDouglas Gregor  std::string isysroot;
6771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
678fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// \brief Whether to disable the normal validation performed on precompiled
679fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// headers when they are loaded.
680fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  bool DisableValidation;
681ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6828ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// \brief Whether to disable the use of stat caches in AST files.
6838ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  bool DisableStatCache;
6848ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor
685bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis  /// \brief Whether to accept an AST file with compiler errors.
686bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis  bool AllowASTWithCompilerErrors;
687bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis
688057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor  /// \brief The current "generation" of the module file import stack, which
689057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor  /// indicates how many separate module file load operations have occurred.
690057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor  unsigned CurrentGeneration;
691057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor
69212dcc64eebf7aaffb71392fba74fcb69f35d3b2eArgyrios Kyrtzidis  typedef llvm::DenseMap<unsigned, SwitchCase *> SwitchCaseMapTy;
6933c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Mapping from switch-case IDs in the chain to switch-case statements
694e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  ///
695e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// Statements usually don't have IDs, but switch cases need them, so that the
696e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// switch statement can refer to them.
69712dcc64eebf7aaffb71392fba74fcb69f35d3b2eArgyrios Kyrtzidis  SwitchCaseMapTy SwitchCaseStmts;
698025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
69912dcc64eebf7aaffb71392fba74fcb69f35d3b2eArgyrios Kyrtzidis  SwitchCaseMapTy *CurrSwitchCaseStmts;
700b88acb018a0d5e897ce291da2664edfd7bd58f5cArgyrios Kyrtzidis
7014fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  /// \brief The number of stat() calls that hit/missed the stat
7024fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  /// cache.
7034fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  unsigned NumStatHits, NumStatMisses;
7044fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor
7057f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// \brief The number of source location entries de-serialized from
7067f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// the PCH file.
7077f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  unsigned NumSLocEntriesRead;
7087f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor
7093c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The number of source location entries in the chain.
710518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl  unsigned TotalNumSLocEntries;
711518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl
7123e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  /// \brief The number of statements (and expressions) de-serialized
7133c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// from the chain.
7143e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  unsigned NumStatementsRead;
7153e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor
7163e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  /// \brief The total number of statements (and expressions) stored
7173c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// in the chain.
7183e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  unsigned TotalNumStatements;
7193e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor
7203c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The number of macros de-serialized from the chain.
72137e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor  unsigned NumMacrosRead;
7222512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor
7233c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The total number of macros stored in the chain.
724fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned TotalNumMacros;
725fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl
726725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl  /// \brief The number of selectors that have been read.
727725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl  unsigned NumSelectorsRead;
72883941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor
729fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The number of method pool entries that have been read.
730fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned NumMethodPoolEntriesRead;
73183941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor
732fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The number of times we have looked up a selector in the method
733fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// pool and not found anything interesting.
734fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned NumMethodPoolMisses;
735fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl
736fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The total number of method pool entries in the selector table.
737fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned TotalNumMethodPoolEntries;
73837e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor
7392512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  /// Number of lexical decl contexts read/total.
7402512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts;
7412512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor
7422512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  /// Number of visible decl contexts read/total.
7432512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts;
744ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7451da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  /// Total size of modules, in bits, currently loaded
7461da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  uint64_t TotalModulesSizeInBits;
7471da901467f72d1733704b068e22089813a1962fdJonathan D. Turner
74829ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// \brief Number of Decl/types that are currently deserializing.
74929ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  unsigned NumCurrentElementsDeserializing;
7501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75144d2dbdce49d1fca3826d543ba875bb82f759091Argyrios Kyrtzidis  /// \brief Set true while we are in the process of passing deserialized
75244d2dbdce49d1fca3826d543ba875bb82f759091Argyrios Kyrtzidis  /// "interesting" decls to consumer inside FinishedDeserializing().
75344d2dbdce49d1fca3826d543ba875bb82f759091Argyrios Kyrtzidis  /// This is used as a guard to avoid recursively repeating the process of
75444d2dbdce49d1fca3826d543ba875bb82f759091Argyrios Kyrtzidis  /// passing decls to consumer.
75544d2dbdce49d1fca3826d543ba875bb82f759091Argyrios Kyrtzidis  bool PassingDeclsToConsumer;
75644d2dbdce49d1fca3826d543ba875bb82f759091Argyrios Kyrtzidis
7571da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  /// Number of CXX base specifiers currently loaded
7581da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  unsigned NumCXXBaseSpecifiersLoaded;
7591da901467f72d1733704b068e22089813a1962fdJonathan D. Turner
7601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief An IdentifierInfo that has been loaded but whose top-level
761d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// declarations of the same name have not (yet) been loaded.
762d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  struct PendingIdentifierInfo {
763d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor    IdentifierInfo *II;
764686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    SmallVector<uint32_t, 4> DeclIDs;
765d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  };
7661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7673c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of identifiers that were read while the AST reader was
7681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// (recursively) loading declarations.
7691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
770d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// The declarations on the identifier chain for these identifiers will be
771d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// loaded once the recursive loading has completed.
772d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  std::deque<PendingIdentifierInfo> PendingIdentifierInfos;
7731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7748efca6bb688d32fd7c0d91b504ef3307f97ee66aDouglas Gregor  /// \brief The generation number of each identifier, which keeps track of
7758efca6bb688d32fd7c0d91b504ef3307f97ee66aDouglas Gregor  /// the last time we loaded information about this identifier.
776057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor  llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;
777057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor
778c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// \brief Contains declarations and definitions that will be
779c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// "interesting" to the ASTConsumer, when we get that AST consumer.
780c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  ///
781c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// "Interesting" declarations are those that have data that may
782c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// need to be emitted, such as inline function definitions or
783c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// Objective-C protocols.
784bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis  std::deque<Decl *> InterestingDecls;
785c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor
78639d26c3e499470cd80a3e6f26f11ac681cd9712cAxel Naumann  /// \brief The set of redeclarable declarations that have been deserialized
7872171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor  /// since the last time the declaration chains were linked.
7882171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor  llvm::SmallPtrSet<Decl *, 16> RedeclsDeserialized;
7892171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor
790a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// \brief The list of redeclaration chains that still need to be
791a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// reconstructed.
792a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  ///
793a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// Each element is the global declaration ID of the first declaration in
794a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// the chain. Elements in this vector should be unique; use
795a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// PendingDeclChainsKnown to ensure uniqueness.
796a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  llvm::SmallVector<serialization::DeclID, 16> PendingDeclChains;
797a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor
798a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// \brief Keeps track of the elements added to PendingDeclChains.
799a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  llvm::SmallSet<serialization::DeclID, 16> PendingDeclChainsKnown;
800a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor
801cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  /// \brief The set of Objective-C categories that have been deserialized
802cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  /// since the last time the declaration chains were linked.
803cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
804cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor
805cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  /// \brief The set of Objective-C class definitions that have already been
806cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  /// loaded, for which we will need to check for categories whenever a new
807cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  /// module is loaded.
808cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  llvm::SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
809cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor
8100f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor  typedef llvm::DenseMap<Decl *, llvm::SmallVector<serialization::DeclID, 2> >
8110f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor    MergedDeclsMap;
8120f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor
8130f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor  /// \brief A mapping from canonical declarations to the set of additional
8140f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor  /// (global, previously-canonical) declaration IDs that have been merged with
8150f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor  /// that canonical declaration.
8160f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor  MergedDeclsMap MergedDecls;
8170f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor
818c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  typedef llvm::DenseMap<serialization::GlobalDeclID,
819c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor                         llvm::SmallVector<serialization::DeclID, 2> >
820c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor    StoredMergedDeclsMap;
821c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor
822c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// \brief A mapping from canonical declaration IDs to the set of additional
823c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// declaration IDs that have been merged with that canonical declaration.
824c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  ///
825c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// This is the deserialized representation of the entries in MergedDecls.
826c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// When we query entries in MergedDecls, they will be augmented with entries
827c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// from StoredMergedDecls.
828c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  StoredMergedDeclsMap StoredMergedDecls;
829c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor
830c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// \brief Combine the stored merged declarations for the given canonical
831c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// declaration into the set of merged declarations.
832c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  ///
833c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// \returns An iterator into MergedDecls that corresponds to the position of
834c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// the given canonical declaration.
835c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  MergedDeclsMap::iterator
836c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  combineStoredMergedDecls(Decl *Canon, serialization::GlobalDeclID CanonID);
837c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor
8380895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis  /// \brief Ready to load the previous declaration of the given Decl.
8390895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis  void loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID);
8400895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis
841919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief When reading a Stmt tree, Stmt operands are placed in this stack.
842686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Stmt *, 16> StmtStack;
843919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
844919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief What kind of records we are reading.
845919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  enum ReadingKind {
846919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    Read_Decl, Read_Type, Read_Stmt
847919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  };
848919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
849ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief What kind of records we are reading.
850919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  ReadingKind ReadingKind;
851919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
852919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief RAII object to change the reading kind.
853919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  class ReadingKindTracker {
854c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl    ASTReader &Reader;
855919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    enum ReadingKind PrevKind;
856919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
857f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko    ReadingKindTracker(const ReadingKindTracker &) LLVM_DELETED_FUNCTION;
858f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko    void operator=(const ReadingKindTracker &) LLVM_DELETED_FUNCTION;
859919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
860919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  public:
861c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl    ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
862919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis      : Reader(reader), PrevKind(Reader.ReadingKind) {
863919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis      Reader.ReadingKind = newKind;
864919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    }
865919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
866919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
867919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  };
868919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
8693c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief All predefines buffers in the chain, to be treated as if
8707e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// concatenated.
8717e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  PCHPredefinesBlocks PCHPredefinesBuffers;
87292b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor
873e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// \brief Suggested contents of the predefines buffer, after this
874e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// PCH file has been processed.
875e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  ///
876e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// In most cases, this string will be empty, because the predefines
877e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// buffer computed to build the PCH file will be identical to the
878e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// predefines buffer computed from the command line. However, when
879e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// there are differences that the PCH reader can work around, this
880e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// predefines buffer may contain additional definitions.
881e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  std::string SuggestedPredefines;
8821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
883919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads a statement from the specified cursor.
8841a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Stmt *ReadStmtFromStream(ModuleFile &F);
885919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
886a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor  typedef llvm::PointerIntPair<const FileEntry *, 1, bool> InputFile;
887a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor
888a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor  /// \brief Retrieve the file entry and 'overridden' bit for an input
889a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor  /// file in the given module file.
89038295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  InputFile getInputFile(ModuleFile &F, unsigned ID, bool Complain = true);
891a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor
892b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  /// \brief Get a FileEntry out of stored-in-PCH filename, making sure we take
893b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  /// into account all the necessary relocations.
894686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  const FileEntry *getFileEntry(StringRef filename);
895b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis
896a930dc9b46572cb6e5bb54f3d724e8fe23a6b66eDouglas Gregor  StringRef MaybeAddSystemRootToFilename(ModuleFile &M, std::string &Filename);
8971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
89810bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor  ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
8991d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor                            ModuleFile *ImportedBy,
90038295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor                            llvm::SmallVectorImpl<ModuleFile *> &Loaded,
90138295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor                            unsigned ClientLoadCapabilities);
9021d9d9898ce2b338314161d92f39561a09a2a8b6fDouglas Gregor  ASTReadResult ReadControlBlock(ModuleFile &F,
90338295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor                                 llvm::SmallVectorImpl<ModuleFile *> &Loaded,
90438295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor                                 unsigned ClientLoadCapabilities);
9054825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor  bool ReadASTBlock(ModuleFile &F);
90638295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  bool CheckPredefinesBuffers(bool Complain);
9071a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  bool ParseLineTable(ModuleFile &F, SmallVectorImpl<uint64_t> &Record);
9084825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor  bool ReadSourceManagerBlock(ModuleFile &F);
909f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  llvm::BitstreamCursor &SLocCursorForID(int ID);
9101a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  SourceLocation getImportLocation(ModuleFile *F);
9114825fd7fbb3fe87cdf8da9bccc1361fac45bdf2dDouglas Gregor  bool ReadSubmoduleBlock(ModuleFile &F);
91227ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor  static bool ParseLanguageOptions(const RecordData &Record, bool Complain,
91327ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor                                   ASTReaderListener &Listener);
91427ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor  static bool ParseTargetOptions(const RecordData &Record, bool Complain,
91527ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor                                 ASTReaderListener &Listener);
91627ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor
917c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  struct RecordLocation {
9181a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    RecordLocation(ModuleFile *M, uint64_t O)
919c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl      : F(M), Offset(O) {}
9201a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    ModuleFile *F;
921c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    uint64_t Offset;
922c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  };
923aaec0aa844781dc7c3462ba140e004e589ccd355Sebastian Redl
924393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  QualType readTypeRecord(unsigned Index);
925aaec0aa844781dc7c3462ba140e004e589ccd355Sebastian Redl  RecordLocation TypeCursorForIndex(unsigned Index);
9262cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  void LoadedDecl(unsigned Index, Decl *D);
927496c709a6f08f5c502b6f592ddd9ed40f953a5e5Douglas Gregor  Decl *ReadDeclRecord(serialization::DeclID ID);
9289d31fa75bc05fe4cb903a7701550f22cfb73ea8bArgyrios Kyrtzidis  RecordLocation DeclCursorForID(serialization::DeclID ID,
9299d31fa75bc05fe4cb903a7701550f22cfb73ea8bArgyrios Kyrtzidis                                 unsigned &RawLocation);
9306bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor  void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D);
931a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  void loadPendingDeclChain(serialization::GlobalDeclID ID);
932cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D,
933cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor                          unsigned PreviousGeneration = 0);
934ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
9358f1231b70c2b1f6fe0cee097b447487b26810301Douglas Gregor  RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
9361a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset);
9372dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
938a7b7d1a7394394d33c18f7dda400a9a12cae2c78James Dennett  /// \brief Returns the first preprocessed entity ID that ends after BLoc.
9392dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  serialization::PreprocessedEntityID
9402dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis    findBeginPreprocessedEntity(SourceLocation BLoc) const;
9412dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
942a7b7d1a7394394d33c18f7dda400a9a12cae2c78James Dennett  /// \brief Returns the first preprocessed entity ID that begins after ELoc.
9432dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  serialization::PreprocessedEntityID
9442dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis    findEndPreprocessedEntity(SourceLocation ELoc) const;
9452dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
946a7b7d1a7394394d33c18f7dda400a9a12cae2c78James Dennett  /// \brief Find the next module that contains entities and return the ID
9472dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  /// of the first entry.
9481824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  ///
9491824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// \param SLocMapI points at a chunk of a module that contains no
950a7b7d1a7394394d33c18f7dda400a9a12cae2c78James Dennett  /// preprocessed entities or the entities it contains are not the
951a7b7d1a7394394d33c18f7dda400a9a12cae2c78James Dennett  /// ones we are looking for.
9522dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  serialization::PreprocessedEntityID
9532dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis    findNextPreprocessedEntity(
9542dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis                        GlobalSLocOffsetMapType::const_iterator SLocMapI) const;
9552dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
9561824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// \brief Returns (ModuleFile, Local index) pair for \p GlobalIndex of a
957f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis  /// preprocessed entity.
9581a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  std::pair<ModuleFile *, unsigned>
959f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis    getModulePreprocessedEntity(unsigned GlobalIndex);
960f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis
961632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidis  /// \brief Returns (begin, end) pair for the preprocessed entities of a
962632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidis  /// particular module.
963632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidis  std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
964632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidis    getModulePreprocessedEntities(ModuleFile &Mod) const;
965632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidis
9662093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis  class ModuleDeclIterator {
9672093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    ASTReader *Reader;
9682093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    ModuleFile *Mod;
9692093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    const serialization::LocalDeclID *Pos;
9702093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis
9712093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis  public:
9722093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    typedef const Decl *value_type;
9732093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    typedef value_type&         reference;
9742093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    typedef value_type*         pointer;
9752093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis
9762093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    ModuleDeclIterator() : Reader(0), Mod(0), Pos(0) { }
9772093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis
9782093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod,
9792093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis                       const serialization::LocalDeclID *Pos)
9802093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      : Reader(Reader), Mod(Mod), Pos(Pos) { }
9812093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis
9822093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    value_type operator*() const {
9832093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *Pos));
9842093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    }
9852093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis
9862093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    ModuleDeclIterator &operator++() {
9872093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      ++Pos;
9882093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      return *this;
9892093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    }
9902093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis
9912093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    ModuleDeclIterator operator++(int) {
9922093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      ModuleDeclIterator Prev(*this);
9932093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      ++Pos;
9942093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      return Prev;
9952093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    }
9962093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis
9972093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    ModuleDeclIterator &operator--() {
9982093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      --Pos;
9992093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      return *this;
10002093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    }
10012093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis
10022093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    ModuleDeclIterator operator--(int) {
10032093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      ModuleDeclIterator Prev(*this);
10042093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      --Pos;
10052093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      return Prev;
10062093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    }
10072093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis
10082093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    friend bool operator==(const ModuleDeclIterator &LHS,
10092093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis                           const ModuleDeclIterator &RHS) {
10102093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      assert(LHS.Reader == RHS.Reader && LHS.Mod == RHS.Mod);
10112093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      return LHS.Pos == RHS.Pos;
10122093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    }
10132093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis
10142093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    friend bool operator!=(const ModuleDeclIterator &LHS,
10152093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis                           const ModuleDeclIterator &RHS) {
10162093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      assert(LHS.Reader == RHS.Reader && LHS.Mod == RHS.Mod);
10172093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis      return LHS.Pos != RHS.Pos;
10182093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    }
10192093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis  };
10202093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis
10212093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis  std::pair<ModuleDeclIterator, ModuleDeclIterator>
10222093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis    getModuleFileLevelDecls(ModuleFile &Mod);
10232093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis
1024bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis  void PassInterestingDeclsToConsumer();
10258d39c3ddfc17d9e768a17eb0ce9f11c33bf9d50aArgyrios Kyrtzidis  void PassInterestingDeclToConsumer(Decl *D);
1026bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis
1027917078386b9b5113f33c093e296e10927b00b37eArgyrios Kyrtzidis  void finishPendingActions();
1028917078386b9b5113f33c093e296e10927b00b37eArgyrios Kyrtzidis
1029a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  /// \brief Produce an error diagnostic and return true.
1030a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  ///
1031a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  /// This routine should only be used for fatal errors that have to
10323c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// do with non-routine failures (e.g., corrupted AST file).
1033686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void Error(StringRef Msg);
1034686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
1035686775deca8b8685eb90801495880e3abdd844c2Chris Lattner             StringRef Arg2 = StringRef());
1036a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor
1037f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko  ASTReader(const ASTReader &) LLVM_DELETED_FUNCTION;
1038f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko  void operator=(const ASTReader &) LLVM_DELETED_FUNCTION;
10392cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorpublic:
10403c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Load the AST file and validate its contents against the given
104111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// Preprocessor.
1042e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
1043e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param PP the preprocessor associated with the context in which this
1044e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// precompiled header will be loaded.
1045e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
1046e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param Context the AST context that this precompiled header will be
1047e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// loaded into.
1048e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
1049e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param isysroot If non-NULL, the system include path specified by the
1050e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// user. This is only used with relocatable PCH files. If non-NULL,
1051e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// a relocatable PCH file will use the default path "/".
1052fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  ///
10533c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param DisableValidation If true, the AST reader will suppress most
1054fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// of its regular consistency checking, allowing the use of precompiled
1055fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// headers that cannot be determined to be compatible.
10568ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  ///
10578ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// \param DisableStatCache If true, the AST reader will ignore the
10588ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// stat cache in the AST files. This performance pessimization can
10598ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// help when an AST file is being used in cases where the
10608ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// underlying files in the file system may have changed, but
10618ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// parsing should still continue.
1062bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis  ///
1063bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis  /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an
1064bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis  /// AST file the was created out of an AST with compiler errors,
1065bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis  /// otherwise it will reject it.
1066f8a1e51c48761ee1d7803c3fa35ac94f42ebb55eDouglas Gregor  ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot = "",
1067bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis            bool DisableValidation = false, bool DisableStatCache = false,
1068bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis            bool AllowASTWithCompilerErrors = false);
10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1070c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ~ASTReader();
10712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
10722dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  SourceManager &getSourceManager() const { return SourceMgr; }
1073ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
107438295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  /// \brief Flags that indicate what kind of AST loading failures the client
107538295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  /// of the AST reader can directly handle.
107638295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  ///
107738295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  /// When a client states that it can handle a particular kind of failure,
107838295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  /// the AST reader will not emit errors when producing that kind of failure.
107938295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  enum LoadFailureCapabilities {
108038295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor    /// \brief The client can't handle any AST loading failures.
108138295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor    ARR_None = 0,
108238295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor    /// \brief The client can handle an AST file that cannot load because it
108338295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor    /// is out-of-date relative to its input files.
108438295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor    ARR_OutOfDate = 0x1,
108538295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor    /// \brief The client can handle an AST file that cannot load because it
108638295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor    /// was built with a different version of Clang.
108738295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor    ARR_VersionMismatch = 0x2,
108838295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor    /// \brief The client can handle an AST file that cannot load because it's
108938295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor    /// compiled configuration doesn't match that of the context it was
109038295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor    /// loaded into.
109138295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor    ARR_ConfigurationMismatch = 0x4
109238295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  };
109338295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor
109410bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor  /// \brief Load the AST file designated by the given file name.
109538295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  ///
109638295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  /// \param FileName The name of the AST file to load.
109738295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  ///
109838295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  /// \param Type The kind of AST being loaded, e.g., PCH, module, main file,
109938295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  /// or preamble.
110038295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  ///
110138295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  /// \param ClientLoadCapabilities The set of client load-failure
110238295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  /// capabilities, represented as a bitset of the enumerators of
110338295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  /// LoadFailureCapabilities.
110438295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor  ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type,
110538295beb73db5f90bfcf31625fb81dbc3b96290aDouglas Gregor                        unsigned ClientLoadCapabilities);
11061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11075e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  /// \brief Make the entities in the given module and any of its (non-explicit)
11085e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  /// submodules visible to name lookup.
11095e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  ///
11105e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  /// \param Mod The module whose names should be made visible.
11115e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  ///
111216ae9de07730832945204877d752db7f1c070962James Dennett  /// \param NameVisibility The level of visibility to give the names in the
111316ae9de07730832945204877d752db7f1c070962James Dennett  /// module.  Visibility can only be increased over time.
11145e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  void makeModuleVisible(Module *Mod,
11155e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor                         Module::NameVisibilityKind NameVisibility);
11165e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor
1117ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// \brief Make the names within this set of hidden names visible.
1118ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  void makeNamesVisible(const HiddenNames &Names);
1119ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
11203c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set the AST callbacks listener.
1121571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  void setListener(ASTReaderListener *listener) {
112211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    Listener.reset(listener);
112311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
11241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11253c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set the AST deserialization listener.
1126571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  void setDeserializationListener(ASTDeserializationListener *Listener);
112730c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl
1128359427794704666ff7a5a933ace11c5256fa3af7Douglas Gregor  /// \brief Initializes the ASTContext
1129359427794704666ff7a5a933ace11c5256fa3af7Douglas Gregor  void InitializeContext();
11302cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1131c24a1eef40207457692a1ad597cefdd0dc8fa149Jonathan D. Turner  /// \brief Add in-memory (virtual file) buffer.
1132c24a1eef40207457692a1ad597cefdd0dc8fa149Jonathan D. Turner  void addInMemoryBuffer(StringRef &FileName, llvm::MemoryBuffer *Buffer) {
1133c24a1eef40207457692a1ad597cefdd0dc8fa149Jonathan D. Turner    ModuleMgr.addInMemoryBuffer(FileName, Buffer);
1134b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis  }
1135b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis
1136ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// \brief Finalizes the AST reader's state before writing an AST file to
1137ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// disk.
1138ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  ///
1139ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// This operation may undo temporary state in the AST that should not be
1140ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// emitted.
1141ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  void finalizeForWriting();
1142ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
1143e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor  /// \brief Retrieve the module manager.
1144e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor  ModuleManager &getModuleManager() { return ModuleMgr; }
1145e19944c93961b7618f4f3f3185f698f46369ea54Steve Naroff
1146d10a381d92a60d4f4c126c4e81045c8ad4636a0bDouglas Gregor  /// \brief Retrieve the preprocessor.
1147712f2fcb70ae2eb0cb684d565e7d2cb76881006bDouglas Gregor  Preprocessor &getPreprocessor() const { return PP; }
1148ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
114911407b89c9d7ce8bc31869b0a7aae06add49e3dcDouglas Gregor  /// \brief Retrieve the name of the original source file name for the primary
115011407b89c9d7ce8bc31869b0a7aae06add49e3dcDouglas Gregor  /// module file.
115111407b89c9d7ce8bc31869b0a7aae06add49e3dcDouglas Gregor  const std::string &getOriginalSourceFile() {
115211407b89c9d7ce8bc31869b0a7aae06add49e3dcDouglas Gregor    return ModuleMgr.getPrimaryModule().OriginalSourceFileName;
115311407b89c9d7ce8bc31869b0a7aae06add49e3dcDouglas Gregor  }
1154b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor
11553c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Retrieve the name of the original source file name directly from
11563c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// the AST file, without actually loading the AST file.
11573c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  static std::string getOriginalSourceFile(const std::string &ASTFileName,
1158389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis                                           FileManager &FileMgr,
1159d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie                                           DiagnosticsEngine &Diags);
1160b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor
116127ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor  /// \brief Determine whether the given AST file is acceptable to load into a
116227ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor  /// translation unit with the given language and target options.
116327ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor  static bool isAcceptableASTFile(StringRef Filename,
116427ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor                                  FileManager &FileMgr,
116527ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor                                  const LangOptions &LangOpts,
116627ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor                                  const TargetOptions &TargetOpts);
116727ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor
1168e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// \brief Returns the suggested contents of the predefines buffer,
1169e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// which contains a (typically-empty) subset of the predefines
1170e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// build prior to including the precompiled header.
1171e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
1172e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis
1173e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  /// \brief Read a preallocated preprocessed entity from the external source.
1174e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  ///
1175e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  /// \returns null if an error occurred that prevented the preprocessed
1176e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  /// entity from being loaded.
1177e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  virtual PreprocessedEntity *ReadPreprocessedEntity(unsigned Index);
1178e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor
11792dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  /// \brief Returns a pair of [Begin, End) indices of preallocated
11801824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// preprocessed entities that \p Range encompasses.
11812dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  virtual std::pair<unsigned, unsigned>
11822dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis      findPreprocessedEntitiesInRange(SourceRange Range);
1183ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1184f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis  /// \brief Optionally returns true or false if the preallocated preprocessed
11851824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// entity with index \p Index came from file \p FID.
1186f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis  virtual llvm::Optional<bool> isPreprocessedEntityInFileID(unsigned Index,
1187f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis                                                            FileID FID);
11882dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
1189cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// \brief Read the header file information for the given file entry.
1190cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE);
1191cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
1192d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
1193f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis
1194f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  /// \brief Returns the number of source locations found in the chain.
11950fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  unsigned getTotalNumSLocs() const {
11960fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl    return TotalNumSLocEntries;
11970fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  }
11980fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl
1199f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  /// \brief Returns the number of identifiers found in the chain.
1200f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  unsigned getTotalNumIdentifiers() const {
1201f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl    return static_cast<unsigned>(IdentifiersLoaded.size());
1202f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  }
1203f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl
1204a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// \brief Returns the number of macros found in the chain.
1205a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  unsigned getTotalNumMacros() const {
1206a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor    return static_cast<unsigned>(MacrosLoaded.size());
1207a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  }
1208a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor
1209e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of types found in the chain.
121077a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  unsigned getTotalNumTypes() const {
121177a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl    return static_cast<unsigned>(TypesLoaded.size());
121277a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  }
121377a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl
1214e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of declarations found in the chain.
121577a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  unsigned getTotalNumDecls() const {
121677a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl    return static_cast<unsigned>(DeclsLoaded.size());
121777a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  }
121877a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl
121926ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief Returns the number of submodules known.
122026ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  unsigned getTotalNumSubmodules() const {
122126ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor    return static_cast<unsigned>(SubmodulesLoaded.size());
122226ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  }
122326ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
1224e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of selectors found in the chain.
1225e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  unsigned getTotalNumSelectors() const {
1226e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl    return static_cast<unsigned>(SelectorsLoaded.size());
1227e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  }
1228e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl
12294c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// \brief Returns the number of preprocessed entities known to the AST
12304c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// reader.
12314c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  unsigned getTotalNumPreprocessedEntities() const {
12324c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    unsigned Result = 0;
12335d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner    for (ModuleConstIterator I = ModuleMgr.begin(),
12345d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner        E = ModuleMgr.end(); I != E; ++I) {
1235e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis      Result += (*I)->NumPreprocessedEntities;
12365d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner    }
1237ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12384c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    return Result;
12394c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  }
1240ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12417c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor  /// \brief Returns the number of C++ base specifiers found in the chain.
12421da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  unsigned getTotalNumCXXBaseSpecifiers() const {
12431da901467f72d1733704b068e22089813a1962fdJonathan D. Turner    return NumCXXBaseSpecifiersLoaded;
12441da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  }
1245ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1246833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief Reads a TemplateArgumentLocInfo appropriate for the
1247833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// given TemplateArgument kind.
1248833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLocInfo
12491a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind,
1250833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                             const RecordData &Record, unsigned &Idx);
1251833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
125244f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis  /// \brief Reads a TemplateArgumentLoc.
1253577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl  TemplateArgumentLoc
12541a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ReadTemplateArgumentLoc(ModuleFile &F,
1255577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                          const RecordData &Record, unsigned &Idx);
125644f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis
1257a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall  /// \brief Reads a declarator info from the given record.
12581a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
1259577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                                    const RecordData &Record, unsigned &Idx);
1260a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
12612cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Resolve a type ID into a type, potentially building a new
12622cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// type.
12638538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  QualType GetType(serialization::TypeID ID);
12642cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1265393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  /// \brief Resolve a local type ID within a given AST file into a type.
12661a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  QualType getLocalType(ModuleFile &F, unsigned LocalID);
1267ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1268393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  /// \brief Map a local type ID within a given AST file into a global type ID.
12691a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const;
1270ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1271ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Read a type from the current position in the given record, which
1272393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  /// was read from the given AST file.
12731a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
1274393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor    if (Idx >= Record.size())
1275393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor      return QualType();
1276ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1277393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor    return getLocalType(F, Record[Idx++]);
1278393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  }
1279ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1280ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Map from a local declaration ID within a given module to a
1281409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// global declaration ID.
12822093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis  serialization::DeclID getGlobalDeclID(ModuleFile &F,
12832093e0bc4e436b1b2791d5423fb3274dd37231b8Argyrios Kyrtzidis                                      serialization::LocalDeclID LocalID) const;
1284e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis
12851824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// \brief Returns true if global DeclID \p ID originated from module \p M.
12861a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const;
1287dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis
1288cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  /// \brief Retrieve the module file that owns the given declaration, or NULL
1289cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  /// if the declaration is not from a module file.
1290cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  ModuleFile *getOwningModuleFile(Decl *D);
1291cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor
12921824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// \brief Returns the source location for the decl \p ID.
1293dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis  SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID);
1294ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12952cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Resolve a declaration ID into a declaration, potentially
12962cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// building a new declaration.
12978538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Decl *GetDecl(serialization::DeclID ID);
129876bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual Decl *GetExternalDecl(uint32_t ID);
12992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
130043fd9388d374f29e908e611a686c6137553efa79Jonathan D. Turner  /// \brief Reads a declaration with the given local ID in the given module.
13011a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) {
1302409448c832d27703146b70a1137d86b020f29863Douglas Gregor    return GetDecl(getGlobalDeclID(F, LocalID));
1303409448c832d27703146b70a1137d86b020f29863Douglas Gregor  }
1304409448c832d27703146b70a1137d86b020f29863Douglas Gregor
130543fd9388d374f29e908e611a686c6137553efa79Jonathan D. Turner  /// \brief Reads a declaration with the given local ID in the given module.
1306409448c832d27703146b70a1137d86b020f29863Douglas Gregor  ///
1307409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \returns The requested declaration, casted to the given return type.
1308409448c832d27703146b70a1137d86b020f29863Douglas Gregor  template<typename T>
13091a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) {
1310409448c832d27703146b70a1137d86b020f29863Douglas Gregor    return cast_or_null<T>(GetLocalDecl(F, LocalID));
1311409448c832d27703146b70a1137d86b020f29863Douglas Gregor  }
1312409448c832d27703146b70a1137d86b020f29863Douglas Gregor
1313a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// \brief Map a global declaration ID into the declaration ID used to
1314a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// refer to this declaration within the given module fule.
1315a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  ///
1316a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// \returns the global ID of the given declaration as known in the given
1317a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// module file.
1318a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  serialization::DeclID
1319a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
1320a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor                                  serialization::DeclID GlobalID);
1321a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor
1322ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Reads a declaration ID from the given position in a record in the
1323409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// given module.
1324409448c832d27703146b70a1137d86b020f29863Douglas Gregor  ///
1325409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \returns The declaration ID read from the record, adjusted to a global ID.
13261a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record,
1327409448c832d27703146b70a1137d86b020f29863Douglas Gregor                                   unsigned &Idx);
1328ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1329409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \brief Reads a declaration from the given position in a record in the
1330409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// given module.
13311a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) {
1332409448c832d27703146b70a1137d86b020f29863Douglas Gregor    return GetDecl(ReadDeclID(F, R, I));
1333409448c832d27703146b70a1137d86b020f29863Douglas Gregor  }
1334ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1335409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \brief Reads a declaration from the given position in a record in the
1336409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// given module.
1337409448c832d27703146b70a1137d86b020f29863Douglas Gregor  ///
1338409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \returns The declaration read from this location, casted to the given
1339409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// result type.
1340409448c832d27703146b70a1137d86b020f29863Douglas Gregor  template<typename T>
13411a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1342409448c832d27703146b70a1137d86b020f29863Douglas Gregor    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1343409448c832d27703146b70a1137d86b020f29863Douglas Gregor  }
1344409448c832d27703146b70a1137d86b020f29863Douglas Gregor
1345e92b8a1dbba150e213c4980710fcb59ec5c5c570Douglas Gregor  /// \brief Read a CXXBaseSpecifiers ID form the given record and
1346e92b8a1dbba150e213c4980710fcb59ec5c5c570Douglas Gregor  /// return its global bit offset.
13471a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  uint64_t readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record,
1348e92b8a1dbba150e213c4980710fcb59ec5c5c570Douglas Gregor                                 unsigned &Idx);
1349ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
13507c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor  virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset);
1351ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1352250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// \brief Resolve the offset of a statement into a statement.
1353250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  ///
1354250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// This operation will read a new statement from the external
1355250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// source each time it is called, and is meant to be used via a
1356887e2b375fc5e00084ec7bf3dd050c2ca399a6d2Chris Lattner  /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
135776bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual Stmt *GetExternalDeclStmt(uint64_t Offset);
1358250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor
13596367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
13606367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// specified cursor.  Read the abbreviations that are at the top of the block
13616367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// and then leave the cursor pointing into the block.
13626367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
13636367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner
136476bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// \brief Finds all the visible declarations with a given name.
136576bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// The current implementation of this method just loads the entire
136676bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// lookup table as unmaterialized references.
136776bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual DeclContext::lookup_result
136876bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  FindExternalVisibleDeclsByName(const DeclContext *DC,
136976bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall                                 DeclarationName Name);
137076bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall
13712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Read all of the declarations lexically stored in a
13722cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declaration context.
13732cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
13742cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \param DC The declaration context whose declarations will be
13752cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// read.
13762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
13772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \param Decls Vector that will contain the declarations loaded
13782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// from the external source. The caller is responsible for merging
13792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// these declarations with any declarations already stored in the
13802cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declaration context.
13812cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
13822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \returns true if there was an error while reading the
13832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declarations for this declaration context.
1384ba6ffaf21e465c0926d7fc5fa294ea52f8d45fafDouglas Gregor  virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
1385eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis                                        bool (*isKindWeWant)(Decl::Kind),
1386686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                        SmallVectorImpl<Decl*> &Decls);
13872cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1388dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis  /// \brief Get the decls that are contained in a file in the Offset/Length
13891824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// range. \p Length can be 0 to indicate a point at \p Offset instead of
1390ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// a range.
1391dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis  virtual void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
1392dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis                                   SmallVectorImpl<Decl *> &Decls);
1393dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis
1394c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief Notify ASTReader that we started deserialization of
139529ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// a decl or type so until FinishedDeserializing is called there may be
139629ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// decls that are initializing. Must be paired with FinishedDeserializing.
139729ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  virtual void StartedDeserializing() { ++NumCurrentElementsDeserializing; }
139829ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis
1399c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief Notify ASTReader that we finished the deserialization of
140029ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// a decl or type. Must be paired with StartedDeserializing.
140129ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  virtual void FinishedDeserializing();
140229ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis
1403fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// \brief Function that will be invoked when we begin parsing a new
1404fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// translation unit involving this external AST source.
1405fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  ///
1406fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// This function will provide all of the external definitions to
1407fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// the ASTConsumer.
1408fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  virtual void StartTranslationUnit(ASTConsumer *Consumer);
1409fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor
14103c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Print some statistics about AST usage.
14112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  virtual void PrintStats();
14122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
141323d7df5ce30f4a068e13ad6cb81d473365d260dbDouglas Gregor  /// \brief Dump information about the AST reader to standard error.
141423d7df5ce30f4a068e13ad6cb81d473365d260dbDouglas Gregor  void dump();
1415ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1416e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek  /// Return the amount of memory used by memory buffers, breaking down
1417e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek  /// by heap-backed versus mmap'ed memory.
1418e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek  virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const;
1419e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek
1420668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Initialize the semantic source with the Sema instance
1421668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// being used to perform semantic analysis on the abstract syntax
1422668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// tree.
1423668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  virtual void InitializeSema(Sema &S);
1424668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1425ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar  /// \brief Inform the semantic consumer that Sema is no longer available.
1426ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar  virtual void ForgetSema() { SemaObj = 0; }
1427ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar
1428668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the IdentifierInfo for the named identifier.
1429668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  ///
14304d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// This routine builds a new IdentifierInfo for the given identifier. If any
14314d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// declarations with this name are visible from translation unit scope, their
14324d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// declarations will be deserialized and introduced into the declaration
143388a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  /// chain of the identifier.
1434d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd);
1435686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  IdentifierInfo *get(StringRef Name) {
14364d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar    return get(Name.begin(), Name.end());
14374d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  }
1438668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
143995f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  /// \brief Retrieve an iterator into the set of all identifiers
144095f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  /// in all loaded AST files.
144195f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  virtual IdentifierIterator *getIdentifiers() const;
144295f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor
1443f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// \brief Load the contents of the global method pool for a given
1444f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// selector.
14455ac4b6917aa34fae6da64036539023a6155a3d48Douglas Gregor  virtual void ReadMethodPool(Selector Sel);
1446f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor
1447d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  /// \brief Load the set of namespaces that are known to the external source,
1448d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  /// which will be used during typo correction.
1449d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  virtual void ReadKnownNamespaces(
1450686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                           SmallVectorImpl<NamespaceDecl *> &Namespaces);
1451d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor
1452a862320972e63349524dc9aa744dec1b95f54ba1Douglas Gregor  virtual void ReadTentativeDefinitions(
1453a862320972e63349524dc9aa744dec1b95f54ba1Douglas Gregor                 SmallVectorImpl<VarDecl *> &TentativeDefs);
1454a862320972e63349524dc9aa744dec1b95f54ba1Douglas Gregor
1455a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor  virtual void ReadUnusedFileScopedDecls(
1456a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor                 SmallVectorImpl<const DeclaratorDecl *> &Decls);
1457a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor
14580129b561a1452bf057f6b18b6a1de815d487ab81Douglas Gregor  virtual void ReadDelegatingConstructors(
14590129b561a1452bf057f6b18b6a1de815d487ab81Douglas Gregor                 SmallVectorImpl<CXXConstructorDecl *> &Decls);
14600129b561a1452bf057f6b18b6a1de815d487ab81Douglas Gregor
1461d58a0a55e64a7c410a80e9d6dcd899e61e99cc4dDouglas Gregor  virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls);
1462d58a0a55e64a7c410a80e9d6dcd899e61e99cc4dDouglas Gregor
1463a126f17ca83b985300c1f65cee647bea108db657Douglas Gregor  virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls);
1464a126f17ca83b985300c1f65cee647bea108db657Douglas Gregor
1465ec12ce2f6da44bfc9048772327a3924498099d60Douglas Gregor  virtual void ReadLocallyScopedExternalDecls(
1466ec12ce2f6da44bfc9048772327a3924498099d60Douglas Gregor                 SmallVectorImpl<NamedDecl *> &Decls);
1467ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
14685b9dc7caaef0469babc45dd8e713727a136ce517Douglas Gregor  virtual void ReadReferencedSelectors(
14695b9dc7caaef0469babc45dd8e713727a136ce517Douglas Gregor                 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels);
14705b9dc7caaef0469babc45dd8e713727a136ce517Douglas Gregor
147131e37b2d7b4815fdea6a35d49f33005562f0d494Douglas Gregor  virtual void ReadWeakUndeclaredIdentifiers(
147231e37b2d7b4815fdea6a35d49f33005562f0d494Douglas Gregor                 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI);
147331e37b2d7b4815fdea6a35d49f33005562f0d494Douglas Gregor
1474dfe6543e12eca5c79421378b7fa6b3e8fc403e63Douglas Gregor  virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables);
1475dfe6543e12eca5c79421378b7fa6b3e8fc403e63Douglas Gregor
14766e4a3f5c59664af13e02e9bb58c2810b830e3b96Douglas Gregor  virtual void ReadPendingInstantiations(
1477ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                 SmallVectorImpl<std::pair<ValueDecl *,
14786e4a3f5c59664af13e02e9bb58c2810b830e3b96Douglas Gregor                                           SourceLocation> > &Pending);
14796e4a3f5c59664af13e02e9bb58c2810b830e3b96Douglas Gregor
1480e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Load a selector from disk, registering its ID if it exists.
1481e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  void LoadSelector(Selector Sel);
1482e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl
14832b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
14841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void SetGloballyVisibleDecls(IdentifierInfo *II,
1485686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                               const SmallVectorImpl<uint32_t> &DeclIDs,
1486d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor                               bool Nonrecursive = false);
14871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14880a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor  /// \brief Report a diagnostic.
14890a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor  DiagnosticBuilder Diag(unsigned DiagID);
14900a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor
1491e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor  /// \brief Report a diagnostic.
1492e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
1493e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor
149495eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor  IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
14951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14961a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record,
149795eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor                                    unsigned &Idx) {
149895eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor    return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
14997356a31327be9b3c3434a0c88746028980da5684Chris Lattner  }
15001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
150195eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor  virtual IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) {
15026c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor    // Note that we are loading an identifier.
15036c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor    Deserializing AnIdentifier(this);
15046c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor
15058c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor    return DecodeIdentifierInfo(ID);
15068c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  }
15078c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor
15081a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
1509ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15101a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
151195eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor                                                    unsigned LocalID);
1512ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1513a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// \brief Retrieve the macro with the given ID.
15143ab50fe3fc8311fb68c4f5eb97e9bb3d0041bf1aDouglas Gregor  MacroInfo *getMacro(serialization::MacroID ID, MacroInfo *Hint = 0);
1515a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor
1516a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// \brief Retrieve the global macro ID corresponding to the given local
1517a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  /// ID within the given module file.
1518a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor  serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID);
1519a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor
15207f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// \brief Read the source location entry with index ID.
1521f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  virtual bool ReadSLocEntry(int ID);
15227f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor
152326ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief Retrieve the global submodule ID given a module and its local ID
152426ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// number.
152526ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  serialization::SubmoduleID
152626ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID);
152726ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
152826ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief Retrieve the submodule that corresponds to a global submodule ID.
152926ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  ///
153026ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  Module *getSubmodule(serialization::SubmoduleID GlobalID);
153126ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
15322d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor  /// \brief Retrieve a selector from the given module with its local ID
15332d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor  /// number.
15341a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
15352d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor
15362d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor  Selector DecodeSelector(serialization::SelectorID Idx);
15371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15388451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  virtual Selector GetExternalSelector(serialization::SelectorID ID);
153976bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  uint32_t GetNumExternalSelectors();
1540719770dcfcb3987e8a2377dcca97955301445eb5Douglas Gregor
15411a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
15422d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor    return getLocalSelector(M, Record[Idx++]);
154390cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff  }
1544ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15458451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  /// \brief Retrieve the global selector ID that corresponds to this
15468451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  /// the local selector ID in a given module.
15471a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  serialization::SelectorID getGlobalSelectorID(ModuleFile &F,
15488451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor                                                unsigned LocalID) const;
15496ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
15506ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a declaration name.
15511a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  DeclarationName ReadDeclarationName(ModuleFile &F,
1552393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor                                      const RecordData &Record, unsigned &Idx);
15531a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadDeclarationNameLoc(ModuleFile &F,
15544045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                              DeclarationNameLoc &DNLoc, DeclarationName Name,
15554045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                              const RecordData &Record, unsigned &Idx);
15561a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo,
15574045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                               const RecordData &Record, unsigned &Idx);
15584045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
15591a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info,
15604045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                         const RecordData &Record, unsigned &Idx);
15610a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor
15621a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F,
1563409448c832d27703146b70a1137d86b020f29863Douglas Gregor                                               const RecordData &Record,
15646ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner                                               unsigned &Idx);
15656ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
15661a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F,
1567dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor                                                    const RecordData &Record,
1568dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor                                                    unsigned &Idx);
1569dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor
15708731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// \brief Read a template name.
15711a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record,
15721aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor                                unsigned &Idx);
15738731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis
15748731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// \brief Read a template argument.
15751a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  TemplateArgument ReadTemplateArgument(ModuleFile &F,
1576577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                                        const RecordData &Record,unsigned &Idx);
1577ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1578dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  /// \brief Read a template parameter list.
15791a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  TemplateParameterList *ReadTemplateParameterList(ModuleFile &F,
1580c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                                                   const RecordData &Record,
1581dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis                                                   unsigned &Idx);
1582ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1583dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  /// \brief Read a template argument array.
1584dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  void
1585686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs,
15861a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor                           ModuleFile &F, const RecordData &Record,
1587c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                           unsigned &Idx);
15888731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis
158937ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis  /// \brief Read a UnresolvedSet structure.
15901a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadUnresolvedSet(ModuleFile &F, UnresolvedSetImpl &Set,
159137ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis                         const RecordData &Record, unsigned &Idx);
159237ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis
15930745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis  /// \brief Read a C++ base specifier.
15941a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F,
15955606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky                                        const RecordData &Record,unsigned &Idx);
15960745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis
1597cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  /// \brief Read a CXXCtorInitializer array.
1598cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  std::pair<CXXCtorInitializer **, unsigned>
15991a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
1600cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt                          unsigned &Idx);
16018e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis
1602c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  /// \brief Read a source location from raw form.
16031a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, unsigned Raw) const {
16045a4374812c56aa60672e291b07e14d3696bbb5a6Argyrios Kyrtzidis    SourceLocation Loc = SourceLocation::getFromRawEncoding(Raw);
16051a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    assert(ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() &&
1606f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor           "Cannot find offset to remap.");
16071a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second;
1608a64ccefdf0ea4e03ec88805d71b0af74950c7472Argyrios Kyrtzidis    return Loc.getLocWithOffset(Remap);
1609c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  }
1610c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl
16116ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a source location.
16121a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
1613c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                                    const RecordData &Record, unsigned& Idx) {
16141a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    return ReadSourceLocation(ModuleFile, Record[Idx++]);
16156ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  }
16166ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
16176ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a source range.
16181a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  SourceRange ReadSourceRange(ModuleFile &F,
1619c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                              const RecordData &Record, unsigned& Idx);
16206ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
16210a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  /// \brief Read an integral value
16220a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
16230a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor
16240a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  /// \brief Read a signed integral value
16250a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
16263a2f7e42514ddbec983c61826ce85d3071e23e8eDouglas Gregor
162717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Read a floating-point value
162817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  llvm::APFloat ReadAPFloat(const RecordData &Record, unsigned &Idx);
162917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
163068a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor  // \brief Read a string
163127ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor  static std::string ReadString(const RecordData &Record, unsigned &Idx);
163268a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor
16330a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  /// \brief Read a version tuple.
163427ffa6caf965ef20fdef5ae23b81cdc3d05e7afbDouglas Gregor  static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
16350a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor
16361a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
1637409448c832d27703146b70a1137d86b020f29863Douglas Gregor                                 unsigned &Idx);
1638ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
163968a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor  /// \brief Reads attributes from the current stream position.
16401a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadAttributes(ModuleFile &F, AttrVec &Attrs,
16414eb9fc0449ddbd5239ddc3ae6b6e52880f47dcf7Argyrios Kyrtzidis                      const RecordData &Record, unsigned &Idx);
164268a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor
1643919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads a statement.
16441a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Stmt *ReadStmt(ModuleFile &F);
16450b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
1646919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads an expression.
16471a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Expr *ReadExpr(ModuleFile &F);
1648c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor
1649d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  /// \brief Reads a sub-statement operand during statement reading.
1650d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  Stmt *ReadSubStmt() {
1651d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    assert(ReadingKind == Read_Stmt &&
1652d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis           "Should be called only during statement reading!");
1653d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    // Subexpressions are stored from last to first, so the next Stmt we need
1654d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    // is at the back of the stack.
1655d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    assert(!StmtStack.empty() && "Read too many sub statements!");
1656d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    return StmtStack.pop_back_val();
1657d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  }
1658d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis
1659d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  /// \brief Reads a sub-expression operand during statement reading.
1660d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  Expr *ReadSubExpr();
1661d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis
166237e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor  /// \brief Reads the macro record located at the given offset.
16633ab50fe3fc8311fb68c4f5eb97e9bb3d0041bf1aDouglas Gregor  void ReadMacroRecord(ModuleFile &F, uint64_t Offset, MacroInfo *Hint = 0);
1664ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
166586c67d8802a9e0887c31c850188991465ac3c1bdDouglas Gregor  /// \brief Determine the global preprocessed entity ID that corresponds to
166686c67d8802a9e0887c31c850188991465ac3c1bdDouglas Gregor  /// the given local ID within the given module.
1667ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  serialization::PreprocessedEntityID
16681a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
1669ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
16706c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor  /// \brief Note that the identifier has a macro history.
16711329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  ///
16721329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  /// \param II The name of the macro.
16731329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  ///
16746c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor  /// \param IDs The global macro IDs that are associated with this identifier.
16756c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor  void setIdentifierIsMacro(IdentifierInfo *II,
16766c6c54a59a6e7dbe63ff6a9bbab76f6e0c7c8462Douglas Gregor                            ArrayRef<serialization::MacroID> IDs);
1677ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
167888a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  /// \brief Read the set of macros defined by this external macro source.
167988a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  virtual void ReadDefinedMacros();
168088a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor
1681eee242ff426bf79149f221798966e58688383c1eDouglas Gregor  /// \brief Update an out-of-date identifier.
1682eee242ff426bf79149f221798966e58688383c1eDouglas Gregor  virtual void updateOutOfDateIdentifier(IdentifierInfo &II);
1683eee242ff426bf79149f221798966e58688383c1eDouglas Gregor
1684057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor  /// \brief Note that this identifier is up-to-date.
1685057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor  void markIdentifierUpToDate(IdentifierInfo *II);
1686a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor
1687643586fe4fcd42b0978efd3566832ab4dce50367Argyrios Kyrtzidis  /// \brief Load all external visible decls in the given DeclContext.
1688b346d2f419ec7d7ce6b20780d518490338efa7deNick Lewycky  void completeVisibleDeclsMap(const DeclContext *DC);
1689643586fe4fcd42b0978efd3566832ab4dce50367Argyrios Kyrtzidis
16903c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Retrieve the AST context that this AST reader supplements.
1691359427794704666ff7a5a933ace11c5256fa3af7Douglas Gregor  ASTContext &getContext() { return Context; }
1692025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
16936cfc1a8b7582b8433b61222502effb018c534393Douglas Gregor  // \brief Contains declarations that were loaded before we have
16946cfc1a8b7582b8433b61222502effb018c534393Douglas Gregor  // access to a Sema object.
1695686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<NamedDecl *, 16> PreloadedDecls;
1696668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1697668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the semantic analysis object used to analyze the
1698668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// translation unit in which the precompiled header is being
1699668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// imported.
1700668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  Sema *getSema() { return SemaObj; }
1701668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1702668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the identifier table associated with the
1703668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// preprocessor.
1704668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  IdentifierTable &getIdentifierTable();
1705668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1706025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Record that the given ID maps to the given switch-case
1707025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// statement.
1708025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
1709025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1710025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Retrieve the switch-case statement with the given ID.
1711025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SwitchCase *getSwitchCaseWithID(unsigned ID);
17121de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
1713e09a275444576deb2c8d9e2255554242f65d7c00Argyrios Kyrtzidis  void ClearSwitchCaseIDs();
1714aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko
1715aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko  /// \brief Cursors for comments blocks.
1716aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko  SmallVector<std::pair<llvm::BitstreamCursor,
1717aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko                        serialization::ModuleFile *>, 8> CommentsCursors;
1718aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko
1719aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko  /// \brief Loads comments ranges.
1720aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko  void ReadComments();
17212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor};
17222cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
172302602be3ccc3b29da5b91d2502c3419404992409Chris Lattner/// \brief Helper class that saves the current stream position and
172402602be3ccc3b29da5b91d2502c3419404992409Chris Lattner/// then restores it when destroyed.
172502602be3ccc3b29da5b91d2502c3419404992409Chris Lattnerstruct SavedStreamPosition {
172602602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
172702602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { }
17281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
172902602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  ~SavedStreamPosition() {
173002602be3ccc3b29da5b91d2502c3419404992409Chris Lattner    Cursor.JumpToBit(Offset);
173102602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  }
17321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
173302602be3ccc3b29da5b91d2502c3419404992409Chris Lattnerprivate:
173402602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  llvm::BitstreamCursor &Cursor;
173502602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  uint64_t Offset;
173602602be3ccc3b29da5b91d2502c3419404992409Chris Lattner};
17371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1738d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenekinline void PCHValidator::Error(const char *Msg) {
1739d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  Reader.Error(Msg);
1740d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek}
1741d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek
17422cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} // end namespace clang
17432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
17442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#endif
1745