ASTReader.h revision 8b12273c86ede439edf52d35b170fd32b2ed49d4
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"
18668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor#include "clang/Sema/ExternalSemaSource.h"
19c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl#include "clang/AST/DeclarationName.h"
20f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor#include "clang/AST/DeclObjC.h"
21833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall#include "clang/AST/TemplateBase.h"
2288a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor#include "clang/Lex/ExternalPreprocessorSource.h"
236a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor#include "clang/Lex/PreprocessingRecord.h"
240a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor#include "clang/Basic/Diagnostic.h"
25668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor#include "clang/Basic/IdentifierTable.h"
267f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor#include "clang/Basic/SourceManager.h"
2717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor#include "llvm/ADT/APFloat.h"
280a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor#include "llvm/ADT/APInt.h"
290a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor#include "llvm/ADT/APSInt.h"
302cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/ADT/OwningPtr.h"
312cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/ADT/SmallVector.h"
32dc3c0d20375bda7775b2fade05b20e315798b9feDaniel Dunbar#include "llvm/ADT/StringRef.h"
332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/Bitcode/BitstreamReader.h"
349f8eb2032030482b1d3de86e9bee725d93564302Chandler Carruth#include "llvm/System/DataTypes.h"
35d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor#include <deque>
36025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor#include <map>
372cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <string>
382cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <utility>
392cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <vector>
402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
412cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace llvm {
422cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  class MemoryBuffer;
432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
452cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace clang {
462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
477d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregorclass AddrLabelExpr;
480af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregorclass ASTConsumer;
492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass ASTContext;
5068a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregorclass Attr;
512cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass Decl;
522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass DeclContext;
536ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattnerclass NestedNameSpecifier;
546ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattnerclass CXXBaseSpecifier;
556ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattnerclass CXXBaseOrMemberInitializer;
561de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregorclass GotoStmt;
571de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregorclass LabelStmt;
586a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregorclass MacroDefinition;
59668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregorclass NamedDecl;
60571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redlclass ASTDeserializationListener;
6114f79002e58556798e86168c63e48d533287eda5Douglas Gregorclass Preprocessor;
62668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregorclass Sema;
63025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorclass SwitchCase;
64c43b54cbc10654ed59de797898042e1a05265246Sebastian Redlclass ASTReader;
65d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redlclass ASTDeclReader;
66eb19485625c7529ffa644e10829533157a8e8d4fDaniel Dunbarstruct HeaderFileInfo;
6711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis
687e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redlstruct PCHPredefinesBlock {
697e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// \brief The file ID for this predefines buffer in a PCH file.
707e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  FileID BufferID;
717e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl
727e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// \brief This predefines buffer in a PCH file.
737e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  llvm::StringRef Data;
747e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl};
757e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redltypedef llvm::SmallVector<PCHPredefinesBlock, 2> PCHPredefinesBlocks;
767e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl
77c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// \brief Abstract interface for callback invocations by the ASTReader.
7811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis///
79c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// While reading an AST file, the ASTReader will call the methods of the
8011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis/// listener to pass on specific information. Some of the listener methods can
81c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// return true to indicate to the ASTReader that the information (and
82571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl/// consequently the AST file) is invalid.
83571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redlclass ASTReaderListener {
8411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidispublic:
85571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  virtual ~ASTReaderListener();
861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives the language options.
8811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
8911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \returns true to indicate the options are invalid or false otherwise.
9011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual bool ReadLanguageOptions(const LangOptions &LangOpts) {
9111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
9211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives the target triple.
9511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
9611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \returns true to indicate the target triple is invalid or false otherwise.
97dc3c0d20375bda7775b2fade05b20e315798b9feDaniel Dunbar  virtual bool ReadTargetTriple(llvm::StringRef Triple) {
9811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
9911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives the contents of the predefines buffer.
10211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
10330c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl  /// \param Buffers Information about the predefines buffers.
10411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
1053c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param OriginalFileName The original file name for the AST file, which
1063c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// will appear as an entry in the predefines buffer.
1077b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar  ///
10811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \param SuggestedPredefines If necessary, additional definitions are added
10911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// here.
11011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
11111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \returns true to indicate the predefines are invalid or false otherwise.
1127e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
1137b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar                                    llvm::StringRef OriginalFileName,
11411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis                                    std::string &SuggestedPredefines) {
11511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
11611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
1171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives a HeaderFileInfo entry.
11912fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor  virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID) {}
1201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives __COUNTER__ value.
12211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual void ReadCounter(unsigned Value) {}
12311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis};
12411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis
125571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl/// \brief ASTReaderListener implementation to validate the information of
12611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis/// the PCH file against an initialized Preprocessor.
127571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redlclass PCHValidator : public ASTReaderListener {
12811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  Preprocessor &PP;
129c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader &Reader;
1301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  unsigned NumHeaderInfos;
1321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidispublic:
134c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  PCHValidator(Preprocessor &PP, ASTReader &Reader)
13511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    : PP(PP), Reader(Reader), NumHeaderInfos(0) {}
1361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual bool ReadLanguageOptions(const LangOptions &LangOpts);
138dc3c0d20375bda7775b2fade05b20e315798b9feDaniel Dunbar  virtual bool ReadTargetTriple(llvm::StringRef Triple);
1397e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
1407b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar                                    llvm::StringRef OriginalFileName,
14111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis                                    std::string &SuggestedPredefines);
14212fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor  virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID);
14311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual void ReadCounter(unsigned Value);
144d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek
145d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenekprivate:
146d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  void Error(const char *Msg);
14711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis};
1482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
149c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// \brief Reads an AST files chain containing the contents of a translation
150c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// unit.
1512cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor///
152c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// The ASTReader class reads bitstreams (produced by the ASTWriter
1532cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// class) containing the serialized representation of a given
1542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// abstract syntax tree and its supporting data structures. An
155c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// instance of the ASTReader can be attached to an ASTContext object,
156c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// which will provide access to the contents of the AST files.
1572cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor///
158c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// The AST reader provides lazy de-serialization of declarations, as
1592cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// required when traversing the AST. Only those AST nodes that are
1602cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// actually required will be de-serialized.
161c43b54cbc10654ed59de797898042e1a05265246Sebastian Redlclass ASTReader
16288a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  : public ExternalPreprocessorSource,
1636a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor    public ExternalPreprocessingRecordSource,
16488a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor    public ExternalSemaSource,
1658c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor    public IdentifierInfoLookup,
1667f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor    public ExternalIdentifierLookup,
1677f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor    public ExternalSLocEntrySource {
168e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregorpublic:
169c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  enum ASTReadResult { Success, Failure, IgnorePCH };
170d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  friend class PCHValidator;
171d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl  friend class ASTDeclReader;
172e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregorprivate:
173c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief The receiver of some callbacks invoked by ASTReader.
174571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  llvm::OwningPtr<ASTReaderListener> Listener;
1751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17630c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl  /// \brief The receiver of deserialization events.
177571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  ASTDeserializationListener *DeserializationListener;
17830c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl
17911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  SourceManager &SourceMgr;
18011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  FileManager &FileMgr;
18111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  Diagnostic &Diags;
1821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
183668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief The semantic analysis object that will be processing the
1843c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// AST files and the translation unit that uses it.
185668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  Sema *SemaObj;
186668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
18714f79002e58556798e86168c63e48d533287eda5Douglas Gregor  /// \brief The preprocessor that will be loading the source file.
18811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  Preprocessor *PP;
18914f79002e58556798e86168c63e48d533287eda5Douglas Gregor
1903c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The AST context into which we'll read the AST files.
191d1d64a027554b635d644957ef071ec04ea1f7063Chris Lattner  ASTContext *Context;
19252e7108f51a4a9f4d6e84f33fb594d06e1d79560Douglas Gregor
1930af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor  /// \brief The AST consumer.
1940af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor  ASTConsumer *Consumer;
1950af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor
1969137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl  /// \brief Information that is needed for every file in the chain.
1979137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl  struct PerFileData {
1989137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    PerFileData();
199501c1036560bb407f9be6834931253f0929cca86Douglas Gregor    ~PerFileData();
2009137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
2013c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// \brief The AST stat cache installed for this file, if any.
2029137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    ///
2033c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// The dynamic type of this stat cache is always ASTStatCache
2049137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    void *StatCache;
2056367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner
2063c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// \brief The bitstream reader from which we'll read the AST file.
2079137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    llvm::BitstreamReader StreamFile;
2089137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    llvm::BitstreamCursor Stream;
2099137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
21004e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl    /// \brief The size of this file, in bits.
21104e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl    uint64_t SizeInBits;
21204e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl
2139137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    /// \brief The cursor to the start of the preprocessor block, which stores
2149137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    /// all of the macro definitions.
2159137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    llvm::BitstreamCursor MacroCursor;
21688a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor
2179137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    /// DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block. It
2189137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    /// has read all the abbreviations at the start of the block and is ready to
2199137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    /// jump around with these in context.
2209137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    llvm::BitstreamCursor DeclsCursor;
2212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2223c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// \brief The file name of the AST file.
2239137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    std::string FileName;
2240a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor
2259137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    /// \brief The memory buffer that stores the data associated with
2263c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// this AST file.
2279137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    llvm::OwningPtr<llvm::MemoryBuffer> Buffer;
2282cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2299137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    /// \brief Cursor used to read source location entries.
2309137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    llvm::BitstreamCursor SLocEntryCursor;
2319137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
2323c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// \brief The number of source location entries in this AST file.
2339137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    unsigned LocalNumSLocEntries;
2349137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
235518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl    /// \brief Offsets for all of the source location entries in the
2363c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// AST file.
237518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl    const uint32_t *SLocOffsets;
238518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl
2393c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// \brief The number of types in this AST file.
2409137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    unsigned LocalNumTypes;
2419137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
24212d6da0675fa7df09e3f078995774b350e3a4652Sebastian Redl    /// \brief Offset of each type within the bitstream, indexed by the
24312d6da0675fa7df09e3f078995774b350e3a4652Sebastian Redl    /// type ID, or the representation of a Type*.
24412d6da0675fa7df09e3f078995774b350e3a4652Sebastian Redl    const uint32_t *TypeOffsets;
24512d6da0675fa7df09e3f078995774b350e3a4652Sebastian Redl
2463c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// \brief The number of declarations in this AST file.
2479137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl    unsigned LocalNumDecls;
24893fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl
2492da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    /// \brief Offset of each declaration within the bitstream, indexed
2502da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    /// by the declaration ID (-1).
2512da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    const uint32_t *DeclOffsets;
2522da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl
2533c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// \brief The number of identifiers in this AST file.
2542da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    unsigned LocalNumIdentifiers;
2552da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl
2562da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    /// \brief Offsets into the identifier table data.
2572da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    ///
2582da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    /// This array is indexed by the identifier ID (-1), and provides
2592da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    /// the offset into IdentifierTableData where the string data is
2602da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    /// stored.
2612da08f9d8dff5f2a0ffb0cef72db80f03900a2cfSebastian Redl    const uint32_t *IdentifierOffsets;
26212d6da0675fa7df09e3f078995774b350e3a4652Sebastian Redl
26393fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl    /// \brief Actual data for the on-disk hash table.
26493fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl    ///
26593fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl    // This pointer points into a memory buffer, where the on-disk hash
26693fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl    // table for identifiers actually lives.
26793fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl    const char *IdentifierTableData;
26893fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl
26993fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl    /// \brief A pointer to an on-disk hash table of opaque type
27093fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl    /// IdentifierHashTable.
27193fb9ed05655512cb14022c667058c078ca90b3cSebastian Redl    void *IdentifierLookupTable;
27204e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl
27304e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl    /// \brief The number of macro definitions in this file.
27404e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl    unsigned LocalNumMacroDefinitions;
27504e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl
27604e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl    /// \brief Offsets of all of the macro definitions in the preprocessing
2773c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// record in the AST file.
27804e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl    const uint32_t *MacroDefinitionOffsets;
27904e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl
28004e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl    /// \brief The number of preallocated preprocessing entities in the
28104e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl    /// preprocessing record.
28204e6fd4a5ceded0a442a6b3e6b87057b9d643fe3Sebastian Redl    unsigned NumPreallocatedPreprocessingEntities;
283320198303df7c16950d83ae79c3f702b84badcf7Fariborz Jahanian
284059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl    /// \brief A pointer to an on-disk hash table of opaque type
2853c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    /// ASTSelectorLookupTable.
286059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl    ///
287725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl    /// This hash table provides the IDs of all selectors, and the associated
288725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl    /// instance and factory methods.
289725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl    void *SelectorLookupTable;
290059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl
291725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl    /// \brief A pointer to the character data that comprises the selector table
292059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl    ///
293059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl    /// The SelectorOffsets table refers into this memory.
294725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl    const unsigned char *SelectorLookupTableData;
295059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl
296059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl    /// \brief Offsets into the method pool lookup table's data array
297059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl    /// where each selector resides.
298059612dd3429cef2d61f11950f3d93a40182bf69Sebastian Redl    const uint32_t *SelectorOffsets;
299725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl
300725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl    /// \brief The number of selectors new to this file.
301725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl    ///
302725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl    /// This is the number of entries in SelectorOffsets.
303725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl    unsigned LocalNumSelectors;
3049137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl  };
3059137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
3063c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The chain of AST files. The first entry is the one named by the
3079137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl  /// user, the last one is the one that doesn't depend on anything further.
308190faf7c30890479925193b074571e5dc30c3f53Sebastian Redl  /// That is, the entry I was created with -include-pch I+1.
3099137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl  llvm::SmallVector<PerFileData*, 2> Chain;
3109137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
3113c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Types that have already been loaded from the chain.
3121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
3131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// When the pointer at index I is non-NULL, the type with
3143c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// ID = (I + 1) << FastQual::Width has already been loaded
3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::vector<QualType> TypesLoaded;
3162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
3175d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// \brief Map that provides the ID numbers of each type within the
3185d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// output stream, plus those deserialized from a chained PCH.
3195d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  ///
3205d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// The ID numbers of types are consecutive (in order of discovery)
3215d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// and start at 1. 0 is reserved for NULL. When types are actually
3225d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// stored in the stream, the ID number is shifted by 2 bits to
3235d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// allow for the const/volatile qualifiers.
3245d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  ///
3255d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// Keys in the map never have const/volatile qualifiers.
3265d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  serialization::TypeIdxMap TypeIdxs;
3275d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis
3283c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Declarations that have already been loaded from the chain.
3292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
3308f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  /// When the pointer at index I is non-NULL, the declaration with ID
3318f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  /// = I + 1 has already been loaded.
3328f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  std::vector<Decl *> DeclsLoaded;
3332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
3348538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  typedef llvm::DenseMap<serialization::DeclID,
3358538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl                         std::pair<PerFileData *, uint64_t> >
3360b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl      DeclReplacementMap;
3370b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl  /// \brief Declarations that have been replaced in a later file in the chain.
3380b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl  DeclReplacementMap ReplacedDecls;
3390b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl
3400fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  /// \brief Information about the contents of a DeclContext.
3410fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  struct DeclContextInfo {
342074dcc8ef8c5df7a155c85648e8eae786bee6cabArgyrios Kyrtzidis    void *NameLookupTableData; // a ASTDeclContextNameLookupTable.
3438538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl    const serialization::DeclID *LexicalDecls;
344681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl    unsigned NumLexicalDecls;
3450fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  };
3460fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  typedef llvm::SmallVector<DeclContextInfo, 1> DeclContextInfos;
3470fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  typedef llvm::DenseMap<const DeclContext *, DeclContextInfos>
3482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor    DeclContextOffsetsMap;
3492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
3502cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Offsets of the lexical and visible declarations for each
3512cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// DeclContext.
3522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  DeclContextOffsetsMap DeclContextOffsets;
3532cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
3548538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  typedef llvm::DenseMap<serialization::DeclID, serialization::DeclID>
3558538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl      FirstLatestDeclIDMap;
356a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis  /// \brief Map of first declarations from a chained PCH that point to the
3573c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// most recent declarations in another AST file.
358a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis  FirstLatestDeclIDMap FirstLatestDeclIDs;
359a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis
360681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl  /// \brief Read the records that describe the contents of declcontexts.
361681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl  bool ReadDeclContextStorage(llvm::BitstreamCursor &Cursor,
362681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl                              const std::pair<uint64_t, uint64_t> &Offsets,
363681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl                              DeclContextInfo &Info);
364681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl
3652b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// \brief A vector containing identifiers that have already been
3662b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// loaded.
3672b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  ///
3682b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// If the pointer at index I is non-NULL, then it refers to the
3692b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// IdentifierInfo for the identifier with ID=I+1 that has already
3702b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// been loaded.
3712b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  std::vector<IdentifierInfo *> IdentifiersLoaded;
372afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor
3731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief A vector containing selectors that have already been loaded.
37483941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  ///
37583941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// This vector is indexed by the Selector ID (-1). NULL selector
37683941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// entries indicate that the particular selector ID has not yet
37783941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// been loaded.
37883941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  llvm::SmallVector<Selector, 16> SelectorsLoaded;
379725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl
380725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl  /// \brief Method selectors used in a @selector expression. Used for
381725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl  /// implementation of -Wselector.
382725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl  llvm::SmallVector<long long unsigned int,64u> ReferencedSelectorsData;
3836a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor
3846a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor  /// \brief The macro definitions we have already loaded.
3856a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor  llvm::SmallVector<MacroDefinition *, 16> MacroDefinitionsLoaded;
3866a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor
3873c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of external definitions stored in the the chain.
388fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  llvm::SmallVector<uint64_t, 16> ExternalDefinitions;
389fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor
3903c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of tentative definitions stored in the the chain.
3914c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor  llvm::SmallVector<uint64_t, 16> TentativeDefinitions;
392e6bbc01d1c4ec5241df36042e0a4a12a6711934bTanya Lattner
3933c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of unused file scoped decls stored in the the chain.
39449b96d1a382ae9f31456166f1a734d3f7f30b992Argyrios Kyrtzidis  llvm::SmallVector<uint64_t, 16> UnusedFileScopedDecls;
39572b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis
3963c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of weak undeclared identifiers stored in the chain.
39772b90571b1783b17c3f2204cec5ca440edc38beeArgyrios Kyrtzidis  llvm::SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
3984c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor
3993c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of locally-scoped external declarations stored in the chain
40014c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor  llvm::SmallVector<uint64_t, 16> LocallyScopedExternalDecls;
40114c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor
4023c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of ext_vector type declarations stored in the the chain.
403b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor  llvm::SmallVector<uint64_t, 4> ExtVectorDecls;
404b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor
4053c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of VTable uses of CXXRecordDecls stored in the chain.
406d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis  llvm::SmallVector<uint64_t, 64> VTableUses;
407d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis
4083c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of dynamic CXXRecord declarations stored in the chain.
409d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis  llvm::SmallVector<uint64_t, 16> DynamicClasses;
410d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis
4113c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of pending implicit instantiations stored in the chain.
4120e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis  llvm::SmallVector<uint64_t, 64> PendingImplicitInstantiations;
4130e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis
4143c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of Sema declaration references stored in the chain.
41576c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis  llvm::SmallVector<uint64_t, 4> SemaDeclRefs;
41676c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis
4173c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of Objective-C category definitions stored in the the chain
418b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor  llvm::SmallVector<uint64_t, 4> ObjCCategoryImpls;
419b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor
4203c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The original file name that was used to build the primary AST file,
4213c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// which may have been modified for relocatable-pch support.
422b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor  std::string OriginalFileName;
423b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor
4243c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The actual original file name that was used to build the primary
4253c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// AST file.
4267b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar  std::string ActualOriginalFileName;
4277b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar
428e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \brief Whether this precompiled header is a relocatable PCH file.
429e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  bool RelocatablePCH;
4301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief The system include root to be used when loading the
432e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// precompiled header.
433e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  const char *isysroot;
4341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
435fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// \brief Whether to disable the normal validation performed on precompiled
436fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// headers when they are loaded.
437fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  bool DisableValidation;
438fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor
4393c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Mapping from switch-case IDs in the chain to switch-case statements
440025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  std::map<unsigned, SwitchCase *> SwitchCaseStmts;
441025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
4423c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Mapping from label statement IDs in the chain to label statements.
4431de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  std::map<unsigned, LabelStmt *> LabelStmts;
4441de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
4451de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// \brief Mapping from label IDs to the set of "goto" statements
4461de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// that point to that label before the label itself has been
4471de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// de-serialized.
4481de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  std::multimap<unsigned, GotoStmt *> UnresolvedGotoStmts;
4491de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
4507d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Mapping from label IDs to the set of address label
4517d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// expressions that point to that label before the label itself has
4527d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// been de-serialized.
4537d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  std::multimap<unsigned, AddrLabelExpr *> UnresolvedAddrLabelExprs;
4547d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
4554fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  /// \brief The number of stat() calls that hit/missed the stat
4564fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  /// cache.
4574fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  unsigned NumStatHits, NumStatMisses;
4584fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor
4597f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// \brief The number of source location entries de-serialized from
4607f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// the PCH file.
4617f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  unsigned NumSLocEntriesRead;
4627f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor
4633c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The number of source location entries in the chain.
464518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl  unsigned TotalNumSLocEntries;
465518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl
4663e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  /// \brief The number of statements (and expressions) de-serialized
4673c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// from the chain.
4683e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  unsigned NumStatementsRead;
4693e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor
4703e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  /// \brief The total number of statements (and expressions) stored
4713c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// in the chain.
4723e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  unsigned TotalNumStatements;
4733e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor
4743c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The number of macros de-serialized from the chain.
47537e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor  unsigned NumMacrosRead;
4762512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor
4773c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The total number of macros stored in the chain.
478fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned TotalNumMacros;
479fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl
480725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl  /// \brief The number of selectors that have been read.
481725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl  unsigned NumSelectorsRead;
48283941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor
483fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The number of method pool entries that have been read.
484fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned NumMethodPoolEntriesRead;
48583941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor
486fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The number of times we have looked up a selector in the method
487fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// pool and not found anything interesting.
488fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned NumMethodPoolMisses;
489fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl
490fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The total number of method pool entries in the selector table.
491fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned TotalNumMethodPoolEntries;
49237e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor
4932512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  /// Number of lexical decl contexts read/total.
4942512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts;
4952512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor
4962512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  /// Number of visible decl contexts read/total.
4972512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts;
49829ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis
49929ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// \brief Number of Decl/types that are currently deserializing.
50029ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  unsigned NumCurrentElementsDeserializing;
5011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief An IdentifierInfo that has been loaded but whose top-level
503d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// declarations of the same name have not (yet) been loaded.
504d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  struct PendingIdentifierInfo {
505d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor    IdentifierInfo *II;
506d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor    llvm::SmallVector<uint32_t, 4> DeclIDs;
507d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  };
5081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5093c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of identifiers that were read while the AST reader was
5101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// (recursively) loading declarations.
5111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
512d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// The declarations on the identifier chain for these identifiers will be
513d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// loaded once the recursive loading has completed.
514d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  std::deque<PendingIdentifierInfo> PendingIdentifierInfos;
5151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
516668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief FIXME: document!
5172bb5ddaff86ee73d2cea7ec1835978afc88a83f0Fariborz Jahanian  llvm::SmallVector<uint64_t, 16> SpecialTypes;
518ad1de006ea080b540e480efc6b86c2e201dbf1ecDouglas Gregor
519c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// \brief Contains declarations and definitions that will be
520c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// "interesting" to the ASTConsumer, when we get that AST consumer.
521c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  ///
522c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// "Interesting" declarations are those that have data that may
523c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// need to be emitted, such as inline function definitions or
524c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// Objective-C protocols.
525bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis  std::deque<Decl *> InterestingDecls;
526c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor
527919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief When reading a Stmt tree, Stmt operands are placed in this stack.
528919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  llvm::SmallVector<Stmt *, 16> StmtStack;
529919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
530919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief What kind of records we are reading.
531919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  enum ReadingKind {
532919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    Read_Decl, Read_Type, Read_Stmt
533919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  };
534919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
535919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief What kind of records we are reading.
536919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  ReadingKind ReadingKind;
537919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
538919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief RAII object to change the reading kind.
539919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  class ReadingKindTracker {
540c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl    ASTReader &Reader;
541919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    enum ReadingKind PrevKind;
542919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
543919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    ReadingKindTracker(const ReadingKindTracker&); // do not implement
544919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    ReadingKindTracker &operator=(const ReadingKindTracker&);// do not implement
545919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
546919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  public:
547c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl    ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
548919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis      : Reader(reader), PrevKind(Reader.ReadingKind) {
549919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis      Reader.ReadingKind = newKind;
550919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    }
551919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
552919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
553919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  };
554919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
5553c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief All predefines buffers in the chain, to be treated as if
5567e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// concatenated.
5577e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  PCHPredefinesBlocks PCHPredefinesBuffers;
55892b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor
559e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// \brief Suggested contents of the predefines buffer, after this
560e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// PCH file has been processed.
561e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  ///
562e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// In most cases, this string will be empty, because the predefines
563e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// buffer computed to build the PCH file will be identical to the
564e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// predefines buffer computed from the command line. However, when
565e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// there are differences that the PCH reader can work around, this
566e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// predefines buffer may contain additional definitions.
567e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  std::string SuggestedPredefines;
5681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
569919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads a statement from the specified cursor.
570919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  Stmt *ReadStmtFromStream(llvm::BitstreamCursor &Cursor);
571919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
572e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  void MaybeAddSystemRootToFilename(std::string &Filename);
5731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
574571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  ASTReadResult ReadASTCore(llvm::StringRef FileName);
575571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  ASTReadResult ReadASTBlock(PerFileData &F);
5767e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  bool CheckPredefinesBuffers();
577518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl  bool ParseLineTable(llvm::SmallVectorImpl<uint64_t> &Record);
578c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReadResult ReadSourceManagerBlock(PerFileData &F);
579c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReadResult ReadSLocEntryRecord(unsigned ID);
580190faf7c30890479925193b074571e5dc30c3f53Sebastian Redl  llvm::BitstreamCursor &SLocCursorForID(unsigned ID);
5810a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor  bool ParseLanguageOptions(const llvm::SmallVectorImpl<uint64_t> &Record);
582aaec0aa844781dc7c3462ba140e004e589ccd355Sebastian Redl
583971dd4498f1118abd12e001add0df06e97669b61Sebastian Redl  typedef std::pair<llvm::BitstreamCursor *, uint64_t> RecordLocation;
584aaec0aa844781dc7c3462ba140e004e589ccd355Sebastian Redl
585aaec0aa844781dc7c3462ba140e004e589ccd355Sebastian Redl  QualType ReadTypeRecord(unsigned Index);
586aaec0aa844781dc7c3462ba140e004e589ccd355Sebastian Redl  RecordLocation TypeCursorForIndex(unsigned Index);
5872cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  void LoadedDecl(unsigned Index, Decl *D);
5888538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Decl *ReadDeclRecord(unsigned Index, serialization::DeclID ID);
5898538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  RecordLocation DeclCursorForIndex(unsigned Index, serialization::DeclID ID);
5902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
591bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis  void PassInterestingDeclsToConsumer();
592bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis
593a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  /// \brief Produce an error diagnostic and return true.
594a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  ///
595a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  /// This routine should only be used for fatal errors that have to
5963c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// do with non-routine failures (e.g., corrupted AST file).
597d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  void Error(const char *Msg);
598a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor
599c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader(const ASTReader&); // do not implement
600c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader &operator=(const ASTReader &); // do not implement
6012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorpublic:
6022cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  typedef llvm::SmallVector<uint64_t, 64> RecordData;
6032cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
6043c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Load the AST file and validate its contents against the given
60511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// Preprocessor.
606e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
607e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param PP the preprocessor associated with the context in which this
608e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// precompiled header will be loaded.
609e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
610e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param Context the AST context that this precompiled header will be
611e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// loaded into.
612e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
613e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param isysroot If non-NULL, the system include path specified by the
614e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// user. This is only used with relocatable PCH files. If non-NULL,
615e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// a relocatable PCH file will use the default path "/".
616fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  ///
6173c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param DisableValidation If true, the AST reader will suppress most
618fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// of its regular consistency checking, allowing the use of precompiled
619fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// headers that cannot be determined to be compatible.
620c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader(Preprocessor &PP, ASTContext *Context, const char *isysroot = 0,
621fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor            bool DisableValidation = false);
6221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6233c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Load the AST file without using any pre-initialized Preprocessor.
62411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
62511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// The necessary information to initialize a Preprocessor later can be
626571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  /// obtained by setting a ASTReaderListener.
627e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
6283c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param SourceMgr the source manager into which the AST file will be loaded
629e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
6303c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param FileMgr the file manager into which the AST file will be loaded.
631e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
632e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param Diags the diagnostics system to use for reporting errors and
6333c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// warnings relevant to loading the AST file.
634e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
635e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param isysroot If non-NULL, the system include path specified by the
636e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// user. This is only used with relocatable PCH files. If non-NULL,
637e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// a relocatable PCH file will use the default path "/".
638fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  ///
6393c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param DisableValidation If true, the AST reader will suppress most
640fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// of its regular consistency checking, allowing the use of precompiled
641fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// headers that cannot be determined to be compatible.
642c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl      ASTReader(SourceManager &SourceMgr, FileManager &FileMgr,
643fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor            Diagnostic &Diags, const char *isysroot = 0,
644fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor            bool DisableValidation = false);
645c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ~ASTReader();
6462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
647b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor  /// \brief Load the precompiled header designated by the given file
648b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor  /// name.
649571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  ASTReadResult ReadAST(const std::string &FileName);
6501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6513c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set the AST callbacks listener.
652571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  void setListener(ASTReaderListener *listener) {
65311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    Listener.reset(listener);
65411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6563c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set the AST deserialization listener.
657571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  void setDeserializationListener(ASTDeserializationListener *Listener);
65830c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl
65911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Set the Preprocessor to use.
6606a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor  void setPreprocessor(Preprocessor &pp);
6611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Sets and initializes the given Context.
66311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  void InitializeContext(ASTContext &Context);
6642cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
6653c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Retrieve the name of the named (primary) AST file
6669137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl  const std::string &getFileName() const { return Chain[0]->FileName; }
667e19944c93961b7618f4f3f3185f698f46369ea54Steve Naroff
6681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the name of the original source file name
669b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor  const std::string &getOriginalSourceFile() { return OriginalFileName; }
670b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor
6713c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Retrieve the name of the original source file name directly from
6723c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// the AST file, without actually loading the AST file.
6733c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  static std::string getOriginalSourceFile(const std::string &ASTFileName,
67493ebb1ba9f35ab5e7bff37c471baeb360eeb0b04Daniel Dunbar                                           Diagnostic &Diags);
675b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor
676e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// \brief Returns the suggested contents of the predefines buffer,
677e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// which contains a (typically-empty) subset of the predefines
678e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// build prior to including the precompiled header.
679e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
6806a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor
6816a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor  /// \brief Read preprocessed entities into the
6826a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor  virtual void ReadPreprocessedEntities();
683e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor
684f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  /// \brief Returns the number of source locations found in the chain.
6850fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  unsigned getTotalNumSLocs() const {
6860fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl    return TotalNumSLocEntries;
6870fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  }
6880fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl
689f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  /// \brief Returns the number of identifiers found in the chain.
690f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  unsigned getTotalNumIdentifiers() const {
691f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl    return static_cast<unsigned>(IdentifiersLoaded.size());
692f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  }
693f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl
694e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of types found in the chain.
69577a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  unsigned getTotalNumTypes() const {
69677a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl    return static_cast<unsigned>(TypesLoaded.size());
69777a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  }
69877a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl
699e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of declarations found in the chain.
70077a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  unsigned getTotalNumDecls() const {
70177a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl    return static_cast<unsigned>(DeclsLoaded.size());
70277a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  }
70377a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl
704e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of selectors found in the chain.
705e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  unsigned getTotalNumSelectors() const {
706e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl    return static_cast<unsigned>(SelectorsLoaded.size());
707e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  }
708e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl
709833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief Reads a TemplateArgumentLocInfo appropriate for the
710833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// given TemplateArgument kind.
711833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLocInfo
712833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind,
713577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                             llvm::BitstreamCursor &DeclsCursor,
714833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                             const RecordData &Record, unsigned &Idx);
715833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
71644f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis  /// \brief Reads a TemplateArgumentLoc.
717577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl  TemplateArgumentLoc
718577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl  ReadTemplateArgumentLoc(llvm::BitstreamCursor &DeclsCursor,
719577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                          const RecordData &Record, unsigned &Idx);
72044f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis
721a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall  /// \brief Reads a declarator info from the given record.
722577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl  TypeSourceInfo *GetTypeSourceInfo(llvm::BitstreamCursor &DeclsCursor,
723577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                                    const RecordData &Record, unsigned &Idx);
724a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
7258871a44ae61cf97ff6fff4c640fadce9ba4cf1b0Argyrios Kyrtzidis  /// \brief Resolve and return the translation unit declaration.
7268871a44ae61cf97ff6fff4c640fadce9ba4cf1b0Argyrios Kyrtzidis  TranslationUnitDecl *GetTranslationUnitDecl();
7278871a44ae61cf97ff6fff4c640fadce9ba4cf1b0Argyrios Kyrtzidis
7282cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Resolve a type ID into a type, potentially building a new
7292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// type.
7308538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  QualType GetType(serialization::TypeID ID);
7312cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
7325d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// \brief Returns the type ID associated with the given type.
7335d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// If the type didn't come from the AST file the ID that is returned is
7345d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// marked as "doesn't exist in AST".
7355d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  serialization::TypeID GetTypeID(QualType T) const;
7365d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis
7375d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// \brief Returns the type index associated with the given type.
7385d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// If the type didn't come from the AST file the index that is returned is
7395d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  /// marked as "doesn't exist in AST".
7405d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis  serialization::TypeIdx GetTypeIdx(QualType T) const;
7415d26768e2661faa7ce0b55ffff4be8b3969fbbf5Argyrios Kyrtzidis
7422cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Resolve a declaration ID into a declaration, potentially
7432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// building a new declaration.
7448538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Decl *GetDecl(serialization::DeclID ID);
74576bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual Decl *GetExternalDecl(uint32_t ID);
7462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
747250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// \brief Resolve the offset of a statement into a statement.
748250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  ///
749250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// This operation will read a new statement from the external
750250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// source each time it is called, and is meant to be used via a
751887e2b375fc5e00084ec7bf3dd050c2ca399a6d2Chris Lattner  /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
75276bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual Stmt *GetExternalDeclStmt(uint64_t Offset);
753250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor
7546367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
7556367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// specified cursor.  Read the abbreviations that are at the top of the block
7566367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// and then leave the cursor pointing into the block.
7576367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
7586367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner
75976bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// \brief Finds all the visible declarations with a given name.
76076bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// The current implementation of this method just loads the entire
76176bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// lookup table as unmaterialized references.
76276bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual DeclContext::lookup_result
76376bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  FindExternalVisibleDeclsByName(const DeclContext *DC,
76476bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall                                 DeclarationName Name);
76576bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall
766a60786b46eaa4766bb57fb3ca4e0191b3f73e42aArgyrios Kyrtzidis  virtual void MaterializeVisibleDecls(const DeclContext *DC);
767a60786b46eaa4766bb57fb3ca4e0191b3f73e42aArgyrios Kyrtzidis
7682cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Read all of the declarations lexically stored in a
7692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declaration context.
7702cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
7712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \param DC The declaration context whose declarations will be
7722cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// read.
7732cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
7742cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \param Decls Vector that will contain the declarations loaded
7752cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// from the external source. The caller is responsible for merging
7762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// these declarations with any declarations already stored in the
7772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declaration context.
7782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
7792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \returns true if there was an error while reading the
7802cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declarations for this declaration context.
78176bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual bool FindExternalLexicalDecls(const DeclContext *DC,
78276bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall                                        llvm::SmallVectorImpl<Decl*> &Decls);
7832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
784c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief Notify ASTReader that we started deserialization of
78529ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// a decl or type so until FinishedDeserializing is called there may be
78629ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// decls that are initializing. Must be paired with FinishedDeserializing.
78729ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  virtual void StartedDeserializing() { ++NumCurrentElementsDeserializing; }
78829ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis
789c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief Notify ASTReader that we finished the deserialization of
79029ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// a decl or type. Must be paired with StartedDeserializing.
79129ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  virtual void FinishedDeserializing();
79229ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis
793fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// \brief Function that will be invoked when we begin parsing a new
794fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// translation unit involving this external AST source.
795fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  ///
796fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// This function will provide all of the external definitions to
797fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// the ASTConsumer.
798fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  virtual void StartTranslationUnit(ASTConsumer *Consumer);
799fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor
8003c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Print some statistics about AST usage.
8012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  virtual void PrintStats();
8022cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
803668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Initialize the semantic source with the Sema instance
804668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// being used to perform semantic analysis on the abstract syntax
805668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// tree.
806668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  virtual void InitializeSema(Sema &S);
807668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
808ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar  /// \brief Inform the semantic consumer that Sema is no longer available.
809ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar  virtual void ForgetSema() { SemaObj = 0; }
810ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar
811668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the IdentifierInfo for the named identifier.
812668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  ///
8134d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// This routine builds a new IdentifierInfo for the given identifier. If any
8144d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// declarations with this name are visible from translation unit scope, their
8154d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// declarations will be deserialized and introduced into the declaration
81688a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  /// chain of the identifier.
817d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd);
818d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  IdentifierInfo *get(llvm::StringRef Name) {
8194d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar    return get(Name.begin(), Name.end());
8204d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  }
821668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
822f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// \brief Load the contents of the global method pool for a given
823f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// selector.
824f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  ///
825f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// \returns a pair of Objective-C methods lists containing the
826f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// instance and factory methods, respectively, with this selector.
8271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual std::pair<ObjCMethodList, ObjCMethodList>
828f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor    ReadMethodPool(Selector Sel);
829f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor
830e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Load a selector from disk, registering its ID if it exists.
831e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  void LoadSelector(Selector Sel);
832e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl
8332b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
8341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void SetGloballyVisibleDecls(IdentifierInfo *II,
835d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor                               const llvm::SmallVectorImpl<uint32_t> &DeclIDs,
836d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor                               bool Nonrecursive = false);
8371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8380a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor  /// \brief Report a diagnostic.
8390a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor  DiagnosticBuilder Diag(unsigned DiagID);
8400a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor
841e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor  /// \brief Report a diagnostic.
842e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
843e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor
8447356a31327be9b3c3434a0c88746028980da5684Chris Lattner  IdentifierInfo *DecodeIdentifierInfo(unsigned Idx);
8451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8467356a31327be9b3c3434a0c88746028980da5684Chris Lattner  IdentifierInfo *GetIdentifierInfo(const RecordData &Record, unsigned &Idx) {
8477356a31327be9b3c3434a0c88746028980da5684Chris Lattner    return DecodeIdentifierInfo(Record[Idx++]);
8487356a31327be9b3c3434a0c88746028980da5684Chris Lattner  }
8491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8508c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  virtual IdentifierInfo *GetIdentifier(unsigned ID) {
8518c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor    return DecodeIdentifierInfo(ID);
8528c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  }
8538c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor
8547f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// \brief Read the source location entry with index ID.
8557f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  virtual void ReadSLocEntry(unsigned ID);
8567f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor
85790cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff  Selector DecodeSelector(unsigned Idx);
8581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
85976bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual Selector GetExternalSelector(uint32_t ID);
86076bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  uint32_t GetNumExternalSelectors();
861719770dcfcb3987e8a2377dcca97955301445eb5Douglas Gregor
86290cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff  Selector GetSelector(const RecordData &Record, unsigned &Idx) {
86390cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff    return DecodeSelector(Record[Idx++]);
86490cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff  }
8656ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
8666ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a declaration name.
8672cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  DeclarationName ReadDeclarationName(const RecordData &Record, unsigned &Idx);
8680a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor
8696ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  NestedNameSpecifier *ReadNestedNameSpecifier(const RecordData &Record,
8706ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner                                               unsigned &Idx);
8716ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
8728731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// \brief Read a template name.
8738731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  TemplateName ReadTemplateName(const RecordData &Record, unsigned &Idx);
8748731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis
8758731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// \brief Read a template argument.
876577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl  TemplateArgument ReadTemplateArgument(llvm::BitstreamCursor &DeclsCursor,
877577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                                        const RecordData &Record,unsigned &Idx);
878dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis
879dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  /// \brief Read a template parameter list.
880dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  TemplateParameterList *ReadTemplateParameterList(const RecordData &Record,
881dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis                                                   unsigned &Idx);
882dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis
883dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  /// \brief Read a template argument array.
884dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  void
885dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs,
886577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                           llvm::BitstreamCursor &DeclsCursor,
887dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis                           const RecordData &Record, unsigned &Idx);
8888731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis
88937ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis  /// \brief Read a UnresolvedSet structure.
89037ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis  void ReadUnresolvedSet(UnresolvedSetImpl &Set,
89137ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis                         const RecordData &Record, unsigned &Idx);
89237ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis
8930745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis  /// \brief Read a C++ base specifier.
8945606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky  CXXBaseSpecifier ReadCXXBaseSpecifier(llvm::BitstreamCursor &DeclsCursor,
8955606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky                                        const RecordData &Record,unsigned &Idx);
8960745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis
8978e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis  /// \brief Read a CXXBaseOrMemberInitializer array.
8988e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis  std::pair<CXXBaseOrMemberInitializer **, unsigned>
8998e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis  ReadCXXBaseOrMemberInitializers(llvm::BitstreamCursor &DeclsCursor,
9008e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis                                  const RecordData &Record, unsigned &Idx);
9018e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis
9026ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a source location.
9036ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  SourceLocation ReadSourceLocation(const RecordData &Record, unsigned& Idx) {
9046ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner    return SourceLocation::getFromRawEncoding(Record[Idx++]);
9056ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  }
9066ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
9076ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a source range.
9086ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  SourceRange ReadSourceRange(const RecordData &Record, unsigned& Idx);
9096ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
9100a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  /// \brief Read an integral value
9110a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
9120a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor
9130a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  /// \brief Read a signed integral value
9140a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
9153a2f7e42514ddbec983c61826ce85d3071e23e8eDouglas Gregor
91617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Read a floating-point value
91717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  llvm::APFloat ReadAPFloat(const RecordData &Record, unsigned &Idx);
91817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
91968a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor  // \brief Read a string
92068a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor  std::string ReadString(const RecordData &Record, unsigned &Idx);
92168a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor
922d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  CXXTemporary *ReadCXXTemporary(const RecordData &Record, unsigned &Idx);
923d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner
92468a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor  /// \brief Reads attributes from the current stream position.
925cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt  void ReadAttributes(llvm::BitstreamCursor &DeclsCursor, AttrVec &Attrs);
92668a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor
927919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads a statement.
928577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl  Stmt *ReadStmt(llvm::BitstreamCursor &Cursor);
9290b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
930919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads an expression.
931577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl  Expr *ReadExpr(llvm::BitstreamCursor &Cursor);
932c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor
933d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  /// \brief Reads a sub-statement operand during statement reading.
934d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  Stmt *ReadSubStmt() {
935d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    assert(ReadingKind == Read_Stmt &&
936d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis           "Should be called only during statement reading!");
937d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    // Subexpressions are stored from last to first, so the next Stmt we need
938d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    // is at the back of the stack.
939d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    assert(!StmtStack.empty() && "Read too many sub statements!");
940d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    return StmtStack.pop_back_val();
941d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  }
942d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis
943d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  /// \brief Reads a sub-expression operand during statement reading.
944d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  Expr *ReadSubExpr();
945d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis
94637e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor  /// \brief Reads the macro record located at the given offset.
947d27d3fc2f1c02e77f43e1af43ed5386474e3d56eSebastian Redl  void ReadMacroRecord(llvm::BitstreamCursor &Stream, uint64_t Offset);
94837e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor
94988a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  /// \brief Read the set of macros defined by this external macro source.
95088a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  virtual void ReadDefinedMacros();
95188a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor
9526a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor  /// \brief Retrieve the macro definition with the given ID.
9538538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  MacroDefinition *getMacroDefinition(serialization::IdentID ID);
954ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl
9553c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Retrieve the AST context that this AST reader supplements.
956d1d64a027554b635d644957ef071ec04ea1f7063Chris Lattner  ASTContext *getContext() { return Context; }
957025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
9586cfc1a8b7582b8433b61222502effb018c534393Douglas Gregor  // \brief Contains declarations that were loaded before we have
9596cfc1a8b7582b8433b61222502effb018c534393Douglas Gregor  // access to a Sema object.
9606cfc1a8b7582b8433b61222502effb018c534393Douglas Gregor  llvm::SmallVector<NamedDecl *, 16> PreloadedDecls;
961668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
962668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the semantic analysis object used to analyze the
963668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// translation unit in which the precompiled header is being
964668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// imported.
965668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  Sema *getSema() { return SemaObj; }
966668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
967668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the identifier table associated with the
968668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// preprocessor.
969668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  IdentifierTable &getIdentifierTable();
970668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
971025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Record that the given ID maps to the given switch-case
972025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// statement.
973025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
974025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
975025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Retrieve the switch-case statement with the given ID.
976025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SwitchCase *getSwitchCaseWithID(unsigned ID);
9771de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
9781de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// \brief Record that the given label statement has been
9791de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// deserialized and has the given ID.
9801de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void RecordLabelStmt(LabelStmt *S, unsigned ID);
9811de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
9821de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// \brief Set the label of the given statement to the label
9831de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// identified by ID.
9841de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  ///
9851de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// Depending on the order in which the label and other statements
9861de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// referencing that label occur, this operation may complete
9871de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// immediately (updating the statement) or it may queue the
9881de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  /// statement to be back-patched later.
9891de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor  void SetLabelOf(GotoStmt *S, unsigned ID);
9907d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
9917d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Set the label of the given expression to the label
9927d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// identified by ID.
9937d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  ///
9947d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// Depending on the order in which the label and other statements
9957d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// referencing that label occur, this operation may complete
9967d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// immediately (updating the statement) or it may queue the
9977d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// statement to be back-patched later.
9987d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void SetLabelOf(AddrLabelExpr *S, unsigned ID);
9992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor};
10002cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
100102602be3ccc3b29da5b91d2502c3419404992409Chris Lattner/// \brief Helper class that saves the current stream position and
100202602be3ccc3b29da5b91d2502c3419404992409Chris Lattner/// then restores it when destroyed.
100302602be3ccc3b29da5b91d2502c3419404992409Chris Lattnerstruct SavedStreamPosition {
100402602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
100502602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { }
10061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100702602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  ~SavedStreamPosition() {
100802602be3ccc3b29da5b91d2502c3419404992409Chris Lattner    Cursor.JumpToBit(Offset);
100902602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  }
10101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
101102602be3ccc3b29da5b91d2502c3419404992409Chris Lattnerprivate:
101202602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  llvm::BitstreamCursor &Cursor;
101302602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  uint64_t Offset;
101402602be3ccc3b29da5b91d2502c3419404992409Chris Lattner};
10151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1016d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenekinline void PCHValidator::Error(const char *Msg) {
1017d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  Reader.Error(Msg);
1018d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek}
1019d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek
10202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} // end namespace clang
10212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
10222cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#endif
1023