zcov: / include/clang/Frontend/PCHReader.h


Files: 1 Branches Taken: 25.0% 1 / 4
Generated: 2010-02-10 01:31 Branches Executed: 50.0% 2 / 4
Line Coverage: 80.0% 32 / 40


Programs: 10 Runs 15090


       1                 : //===--- PCHReader.h - Precompiled Headers Reader ---------------*- C++ -*-===//
       2                 : //
       3                 : //                     The LLVM Compiler Infrastructure
       4                 : //
       5                 : // This file is distributed under the University of Illinois Open Source
       6                 : // License. See LICENSE.TXT for details.
       7                 : //
       8                 : //===----------------------------------------------------------------------===//
       9                 : //
      10                 : //  This file defines the PCHReader class, which reads a precompiled header.
      11                 : //
      12                 : //===----------------------------------------------------------------------===//
      13                 : 
      14                 : #ifndef LLVM_CLANG_FRONTEND_PCH_READER_H
      15                 : #define LLVM_CLANG_FRONTEND_PCH_READER_H
      16                 : 
      17                 : #include "clang/Frontend/PCHBitCodes.h"
      18                 : #include "clang/AST/DeclarationName.h"
      19                 : #include "clang/Sema/ExternalSemaSource.h"
      20                 : #include "clang/AST/DeclObjC.h"
      21                 : #include "clang/AST/Type.h"
      22                 : #include "clang/AST/TemplateBase.h"
      23                 : #include "clang/Lex/ExternalPreprocessorSource.h"
      24                 : #include "clang/Basic/Diagnostic.h"
      25                 : #include "clang/Basic/IdentifierTable.h"
      26                 : #include "clang/Basic/SourceManager.h"
      27                 : #include "llvm/ADT/APFloat.h"
      28                 : #include "llvm/ADT/APInt.h"
      29                 : #include "llvm/ADT/APSInt.h"
      30                 : #include "llvm/ADT/DenseMap.h"
      31                 : #include "llvm/ADT/OwningPtr.h"
      32                 : #include "llvm/ADT/SmallVector.h"
      33                 : #include "llvm/ADT/StringRef.h"
      34                 : #include "llvm/Bitcode/BitstreamReader.h"
      35                 : #include "llvm/System/DataTypes.h"
      36                 : #include <deque>
      37                 : #include <map>
      38                 : #include <string>
      39                 : #include <utility>
      40                 : #include <vector>
      41                 : 
      42                 : namespace llvm {
      43                 :   class MemoryBuffer;
      44                 : }
      45                 : 
      46                 : namespace clang {
      47                 : 
      48                 : class AddrLabelExpr;
      49                 : class ASTConsumer;
      50                 : class ASTContext;
      51                 : class Attr;
      52                 : class Decl;
      53                 : class DeclContext;
      54                 : class GotoStmt;
      55                 : class LabelStmt;
      56                 : class NamedDecl;
      57                 : class Preprocessor;
      58                 : class Sema;
      59                 : class SwitchCase;
      60                 : class PCHReader;
      61                 : struct HeaderFileInfo;
      62                 : 
      63                 : /// \brief Abstract interface for callback invocations by the PCHReader.
      64                 : ///
      65                 : /// While reading a PCH file, the PCHReader will call the methods of the
      66                 : /// listener to pass on specific information. Some of the listener methods can
      67                 : /// return true to indicate to the PCHReader that the information (and
      68                 : /// consequently the PCH file) is invalid.
      69               48: class PCHReaderListener {
      70                 : public:
      71                 :   virtual ~PCHReaderListener();
      72                 : 
      73                 :   /// \brief Receives the language options.
      74                 :   ///
      75                 :   /// \returns true to indicate the options are invalid or false otherwise.
      76                0:   virtual bool ReadLanguageOptions(const LangOptions &LangOpts) {
      77                0:     return false;
      78                 :   }
      79                 : 
      80                 :   /// \brief Receives the target triple.
      81                 :   ///
      82                 :   /// \returns true to indicate the target triple is invalid or false otherwise.
      83                0:   virtual bool ReadTargetTriple(llvm::StringRef Triple) {
      84                0:     return false;
      85                 :   }
      86                 : 
      87                 :   /// \brief Receives the contents of the predefines buffer.
      88                 :   ///
      89                 :   /// \param PCHPredef The start of the predefines buffer in the PCH
      90                 :   /// file.
      91                 :   ///
      92                 :   /// \param PCHBufferID The FileID for the PCH predefines buffer.
      93                 :   ///
      94                 :   /// \param OriginalFileName The original file name for the PCH, which will
      95                 :   /// appear as an entry in the predefines buffer.
      96                 :   ///
      97                 :   /// \param SuggestedPredefines If necessary, additional definitions are added
      98                 :   /// here.
      99                 :   ///
     100                 :   /// \returns true to indicate the predefines are invalid or false otherwise.
     101                 :   virtual bool ReadPredefinesBuffer(llvm::StringRef PCHPredef,
     102                 :                                     FileID PCHBufferID,
     103                 :                                     llvm::StringRef OriginalFileName,
     104                0:                                     std::string &SuggestedPredefines) {
     105                0:     return false;
     106                 :   }
     107                 : 
     108                 :   /// \brief Receives a HeaderFileInfo entry.
     109                0:   virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI) {}
     110                 : 
     111                 :   /// \brief Receives __COUNTER__ value.
     112                0:   virtual void ReadCounter(unsigned Value) {}
     113                 : };
     114                 : 
     115                 : /// \brief PCHReaderListener implementation to validate the information of
     116                 : /// the PCH file against an initialized Preprocessor.
                       34: branch 1 taken
                        0: branch 2 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
     117               34: class PCHValidator : public PCHReaderListener {
     118                 :   Preprocessor &PP;
     119                 :   PCHReader &Reader;
     120                 : 
     121                 :   unsigned NumHeaderInfos;
     122                 : 
     123                 : public:
     124               35:   PCHValidator(Preprocessor &PP, PCHReader &Reader)
     125               35:     : PP(PP), Reader(Reader), NumHeaderInfos(0) {}
     126                 : 
     127                 :   virtual bool ReadLanguageOptions(const LangOptions &LangOpts);
     128                 :   virtual bool ReadTargetTriple(llvm::StringRef Triple);
     129                 :   virtual bool ReadPredefinesBuffer(llvm::StringRef PCHPredef,
     130                 :                                     FileID PCHBufferID,
     131                 :                                     llvm::StringRef OriginalFileName,
     132                 :                                     std::string &SuggestedPredefines);
     133                 :   virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI);
     134                 :   virtual void ReadCounter(unsigned Value);
     135                 : };
     136                 : 
     137                 : /// \brief Reads a precompiled head containing the contents of a
     138                 : /// translation unit.
     139                 : ///
     140                 : /// The PCHReader class reads a bitstream (produced by the PCHWriter
     141                 : /// class) containing the serialized representation of a given
     142                 : /// abstract syntax tree and its supporting data structures. An
     143                 : /// instance of the PCHReader can be attached to an ASTContext object,
     144                 : /// which will provide access to the contents of the PCH file.
     145                 : ///
     146                 : /// The PCH reader provides lazy de-serialization of declarations, as
     147                 : /// required when traversing the AST. Only those AST nodes that are
     148                 : /// actually required will be de-serialized.
     149                 : class PCHReader
     150                 :   : public ExternalPreprocessorSource,
     151                 :     public ExternalSemaSource,
     152                 :     public IdentifierInfoLookup,
     153                 :     public ExternalIdentifierLookup,
     154                 :     public ExternalSLocEntrySource {
     155                 : public:
     156                 :   enum PCHReadResult { Success, Failure, IgnorePCH };
     157                 : 
     158                 : private:
     159                 :   /// \ brief The receiver of some callbacks invoked by PCHReader.
     160                 :   llvm::OwningPtr<PCHReaderListener> Listener;
     161                 : 
     162                 :   SourceManager &SourceMgr;
     163                 :   FileManager &FileMgr;
     164                 :   Diagnostic &Diags;
     165                 : 
     166                 :   /// \brief The semantic analysis object that will be processing the
     167                 :   /// PCH file and the translation unit that uses it.
     168                 :   Sema *SemaObj;
     169                 : 
     170                 :   /// \brief The preprocessor that will be loading the source file.
     171                 :   Preprocessor *PP;
     172                 : 
     173                 :   /// \brief The AST context into which we'll read the PCH file.
     174                 :   ASTContext *Context;
     175                 : 
     176                 :   /// \brief The PCH stat cache installed by this PCHReader, if any.
     177                 :   ///
     178                 :   /// The dynamic type of this stat cache is always PCHStatCache
     179                 :   void *StatCache;
     180                 :       
     181                 :   /// \brief The AST consumer.
     182                 :   ASTConsumer *Consumer;
     183                 : 
     184                 :   /// \brief The bitstream reader from which we'll read the PCH file.
     185                 :   llvm::BitstreamReader StreamFile;
     186                 :   llvm::BitstreamCursor Stream;
     187                 : 
     188                 :   /// \brief The cursor to the start of the preprocessor block, which stores
     189                 :   /// all of the macro definitions.
     190                 :   llvm::BitstreamCursor MacroCursor;
     191                 :       
     192                 :   /// DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block.  It
     193                 :   /// has read all the abbreviations at the start of the block and is ready to
     194                 :   /// jump around with these in context.
     195                 :   llvm::BitstreamCursor DeclsCursor;
     196                 : 
     197                 :   /// \brief The file name of the PCH file.
     198                 :   std::string FileName;
     199                 : 
     200                 :   /// \brief The memory buffer that stores the data associated with
     201                 :   /// this PCH file.
     202                 :   llvm::OwningPtr<llvm::MemoryBuffer> Buffer;
     203                 : 
     204                 :   /// \brief Offset type for all of the source location entries in the
     205                 :   /// PCH file.
     206                 :   const uint32_t *SLocOffsets;
     207                 : 
     208                 :   /// \brief The number of source location entries in the PCH file.
     209                 :   unsigned TotalNumSLocEntries;
     210                 : 
     211                 :   /// \brief Cursor used to read source location entries.
     212                 :   llvm::BitstreamCursor SLocEntryCursor;
     213                 : 
     214                 :   /// \brief Offset of each type within the bitstream, indexed by the
     215                 :   /// type ID, or the representation of a Type*.
     216                 :   const uint32_t *TypeOffsets;
     217                 : 
     218                 :   /// \brief Types that have already been loaded from the PCH file.
     219                 :   ///
     220                 :   /// When the pointer at index I is non-NULL, the type with
     221                 :   /// ID = (I + 1) << 3 has already been loaded from the PCH file.
     222                 :   std::vector<QualType> TypesLoaded;
     223                 : 
     224                 :   /// \brief Offset of each declaration within the bitstream, indexed
     225                 :   /// by the declaration ID (-1).
     226                 :   const uint32_t *DeclOffsets;
     227                 : 
     228                 :   /// \brief Declarations that have already been loaded from the PCH file.
     229                 :   ///
     230                 :   /// When the pointer at index I is non-NULL, the declaration with ID
     231                 :   /// = I + 1 has already been loaded.
     232                 :   std::vector<Decl *> DeclsLoaded;
     233                 : 
     234                 :   typedef llvm::DenseMap<const DeclContext *, std::pair<uint64_t, uint64_t> >
     235                 :     DeclContextOffsetsMap;
     236                 : 
     237                 :   /// \brief Offsets of the lexical and visible declarations for each
     238                 :   /// DeclContext.
     239                 :   DeclContextOffsetsMap DeclContextOffsets;
     240                 : 
     241                 :   /// \brief Actual data for the on-disk hash table.
     242                 :   ///
     243                 :   // This pointer points into a memory buffer, where the on-disk hash
     244                 :   // table for identifiers actually lives.
     245                 :   const char *IdentifierTableData;
     246                 : 
     247                 :   /// \brief A pointer to an on-disk hash table of opaque type
     248                 :   /// IdentifierHashTable.
     249                 :   void *IdentifierLookupTable;
     250                 : 
     251                 :   /// \brief Offsets into the identifier table data.
     252                 :   ///
     253                 :   /// This array is indexed by the identifier ID (-1), and provides
     254                 :   /// the offset into IdentifierTableData where the string data is
     255                 :   /// stored.
     256                 :   const uint32_t *IdentifierOffsets;
     257                 : 
     258                 :   /// \brief A vector containing identifiers that have already been
     259                 :   /// loaded.
     260                 :   ///
     261                 :   /// If the pointer at index I is non-NULL, then it refers to the
     262                 :   /// IdentifierInfo for the identifier with ID=I+1 that has already
     263                 :   /// been loaded.
     264                 :   std::vector<IdentifierInfo *> IdentifiersLoaded;
     265                 : 
     266                 :   /// \brief A pointer to an on-disk hash table of opaque type
     267                 :   /// PCHMethodPoolLookupTable.
     268                 :   ///
     269                 :   /// This hash table provides the instance and factory methods
     270                 :   /// associated with every selector known in the PCH file.
     271                 :   void *MethodPoolLookupTable;
     272                 : 
     273                 :   /// \brief A pointer to the character data that comprises the method
     274                 :   /// pool.
     275                 :   ///
     276                 :   /// The SelectorOffsets table refers into this memory.
     277                 :   const unsigned char *MethodPoolLookupTableData;
     278                 : 
     279                 :   /// \brief The number of selectors stored in the method pool itself.
     280                 :   unsigned TotalSelectorsInMethodPool;
     281                 : 
     282                 :   /// \brief Offsets into the method pool lookup table's data array
     283                 :   /// where each selector resides.
     284                 :   const uint32_t *SelectorOffsets;
     285                 : 
     286                 :   /// \brief The total number of selectors stored in the PCH file.
     287                 :   unsigned TotalNumSelectors;
     288                 : 
     289                 :   /// \brief A vector containing selectors that have already been loaded.
     290                 :   ///
     291                 :   /// This vector is indexed by the Selector ID (-1). NULL selector
     292                 :   /// entries indicate that the particular selector ID has not yet
     293                 :   /// been loaded.
     294                 :   llvm::SmallVector<Selector, 16> SelectorsLoaded;
     295                 : 
     296                 :   /// \brief A sorted array of source ranges containing comments.
     297                 :   SourceRange *Comments;
     298                 : 
     299                 :   /// \brief The number of source ranges in the Comments array.
     300                 :   unsigned NumComments;
     301                 : 
     302                 :   /// \brief The set of external definitions stored in the the PCH
     303                 :   /// file.
     304                 :   llvm::SmallVector<uint64_t, 16> ExternalDefinitions;
     305                 : 
     306                 :   /// \brief The set of tentative definitions stored in the the PCH
     307                 :   /// file.
     308                 :   llvm::SmallVector<uint64_t, 16> TentativeDefinitions;
     309                 : 
     310                 :   /// \brief The set of locally-scoped external declarations stored in
     311                 :   /// the the PCH file.
     312                 :   llvm::SmallVector<uint64_t, 16> LocallyScopedExternalDecls;
     313                 : 
     314                 :   /// \brief The set of ext_vector type declarations stored in the the
     315                 :   /// PCH file.
     316                 :   llvm::SmallVector<uint64_t, 4> ExtVectorDecls;
     317                 : 
     318                 :   /// \brief The set of Objective-C category definitions stored in the
     319                 :   /// the PCH file.
     320                 :   llvm::SmallVector<uint64_t, 4> ObjCCategoryImpls;
     321                 : 
     322                 :   /// \brief The original file name that was used to build the PCH file, which
     323                 :   /// may have been modified for relocatable-pch support.
     324                 :   std::string OriginalFileName;
     325                 : 
     326                 :   /// \brief The actual original file name that was used to build the PCH file.
     327                 :   std::string ActualOriginalFileName;
     328                 : 
     329                 :   /// \brief Whether this precompiled header is a relocatable PCH file.
     330                 :   bool RelocatablePCH;
     331                 : 
     332                 :   /// \brief The system include root to be used when loading the
     333                 :   /// precompiled header.
     334                 :   const char *isysroot;
     335                 : 
     336                 :   /// \brief Mapping from switch-case IDs in the PCH file to
     337                 :   /// switch-case statements.
     338                 :   std::map<unsigned, SwitchCase *> SwitchCaseStmts;
     339                 : 
     340                 :   /// \brief Mapping from label statement IDs in the PCH file to label
     341                 :   /// statements.
     342                 :   std::map<unsigned, LabelStmt *> LabelStmts;
     343                 : 
     344                 :   /// \brief Mapping from label IDs to the set of "goto" statements
     345                 :   /// that point to that label before the label itself has been
     346                 :   /// de-serialized.
     347                 :   std::multimap<unsigned, GotoStmt *> UnresolvedGotoStmts;
     348                 : 
     349                 :   /// \brief Mapping from label IDs to the set of address label
     350                 :   /// expressions that point to that label before the label itself has
     351                 :   /// been de-serialized.
     352                 :   std::multimap<unsigned, AddrLabelExpr *> UnresolvedAddrLabelExprs;
     353                 : 
     354                 :   /// \brief The number of stat() calls that hit/missed the stat
     355                 :   /// cache.
     356                 :   unsigned NumStatHits, NumStatMisses;
     357                 : 
     358                 :   /// \brief The number of source location entries de-serialized from
     359                 :   /// the PCH file.
     360                 :   unsigned NumSLocEntriesRead;
     361                 : 
     362                 :   /// \brief The number of statements (and expressions) de-serialized
     363                 :   /// from the PCH file.
     364                 :   unsigned NumStatementsRead;
     365                 : 
     366                 :   /// \brief The total number of statements (and expressions) stored
     367                 :   /// in the PCH file.
     368                 :   unsigned TotalNumStatements;
     369                 : 
     370                 :   /// \brief The number of macros de-serialized from the PCH file.
     371                 :   unsigned NumMacrosRead;
     372                 : 
     373                 :   /// \brief The number of method pool entries that have been read.
     374                 :   unsigned NumMethodPoolSelectorsRead;
     375                 : 
     376                 :   /// \brief The number of times we have looked into the global method
     377                 :   /// pool and not found anything.
     378                 :   unsigned NumMethodPoolMisses;
     379                 : 
     380                 :   /// \brief The total number of macros stored in the PCH file.
     381                 :   unsigned TotalNumMacros;
     382                 : 
     383                 :   /// Number of lexical decl contexts read/total.
     384                 :   unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts;
     385                 : 
     386                 :   /// Number of visible decl contexts read/total.
     387                 :   unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts;
     388                 : 
     389                 :   /// \brief When a type or declaration is being loaded from the PCH file, an
     390                 :   /// instantance of this RAII object will be available on the stack to
     391                 :   /// indicate when we are in a recursive-loading situation.
     392                 :   class LoadingTypeOrDecl {
     393                 :     PCHReader &Reader;
     394                 :     LoadingTypeOrDecl *Parent;
     395                 : 
     396                 :     LoadingTypeOrDecl(const LoadingTypeOrDecl&); // do not implement
     397                 :     LoadingTypeOrDecl &operator=(const LoadingTypeOrDecl&); // do not implement
     398                 : 
     399                 :   public:
     400                 :     explicit LoadingTypeOrDecl(PCHReader &Reader);
     401                 :     ~LoadingTypeOrDecl();
     402                 :   };
     403                 :   friend class LoadingTypeOrDecl;
     404                 : 
     405                 :   /// \brief If we are currently loading a type or declaration, points to the
     406                 :   /// most recent LoadingTypeOrDecl object on the stack.
     407                 :   LoadingTypeOrDecl *CurrentlyLoadingTypeOrDecl;
     408                 : 
     409                 :   /// \brief An IdentifierInfo that has been loaded but whose top-level
     410                 :   /// declarations of the same name have not (yet) been loaded.
     411              872:   struct PendingIdentifierInfo {
     412                 :     IdentifierInfo *II;
     413                 :     llvm::SmallVector<uint32_t, 4> DeclIDs;
     414                 :   };
     415                 : 
     416                 :   /// \brief The set of identifiers that were read while the PCH reader was
     417                 :   /// (recursively) loading declarations.
     418                 :   ///
     419                 :   /// The declarations on the identifier chain for these identifiers will be
     420                 :   /// loaded once the recursive loading has completed.
     421                 :   std::deque<PendingIdentifierInfo> PendingIdentifierInfos;
     422                 : 
     423                 :   /// \brief FIXME: document!
     424                 :   llvm::SmallVector<uint64_t, 4> SpecialTypes;
     425                 : 
     426                 :   /// \brief Contains declarations and definitions that will be
     427                 :   /// "interesting" to the ASTConsumer, when we get that AST consumer.
     428                 :   ///
     429                 :   /// "Interesting" declarations are those that have data that may
     430                 :   /// need to be emitted, such as inline function definitions or
     431                 :   /// Objective-C protocols.
     432                 :   llvm::SmallVector<Decl *, 16> InterestingDecls;
     433                 : 
     434                 :   /// \brief The file ID for the predefines buffer in the PCH file.
     435                 :   FileID PCHPredefinesBufferID;
     436                 : 
     437                 :   /// \brief Pointer to the beginning of the predefines buffer in the
     438                 :   /// PCH file.
     439                 :   const char *PCHPredefines;
     440                 : 
     441                 :   /// \brief Length of the predefines buffer in the PCH file.
     442                 :   unsigned PCHPredefinesLen;
     443                 : 
     444                 :   /// \brief Suggested contents of the predefines buffer, after this
     445                 :   /// PCH file has been processed.
     446                 :   ///
     447                 :   /// In most cases, this string will be empty, because the predefines
     448                 :   /// buffer computed to build the PCH file will be identical to the
     449                 :   /// predefines buffer computed from the command line. However, when
     450                 :   /// there are differences that the PCH reader can work around, this
     451                 :   /// predefines buffer may contain additional definitions.
     452                 :   std::string SuggestedPredefines;
     453                 : 
     454                 :   void MaybeAddSystemRootToFilename(std::string &Filename);
     455                 : 
     456                 :   PCHReadResult ReadPCHBlock();
     457                 :   bool CheckPredefinesBuffer(llvm::StringRef PCHPredef, FileID PCHBufferID);
     458                 :   bool ParseLineTable(llvm::SmallVectorImpl<uint64_t> &Record);
     459                 :   PCHReadResult ReadSourceManagerBlock();
     460                 :   PCHReadResult ReadSLocEntryRecord(unsigned ID);
     461                 : 
     462                 :   bool ParseLanguageOptions(const llvm::SmallVectorImpl<uint64_t> &Record);
     463                 :   QualType ReadTypeRecord(uint64_t Offset);
     464                 :   void LoadedDecl(unsigned Index, Decl *D);
     465                 :   Decl *ReadDeclRecord(uint64_t Offset, unsigned Index);
     466                 : 
     467                 :   /// \brief Produce an error diagnostic and return true.
     468                 :   ///
     469                 :   /// This routine should only be used for fatal errors that have to
     470                 :   /// do with non-routine failures (e.g., corrupted PCH file).
     471                 :   bool Error(const char *Msg);
     472                 : 
     473                 :   PCHReader(const PCHReader&); // do not implement
     474                 :   PCHReader &operator=(const PCHReader &); // do not implement
     475                 : public:
     476                 :   typedef llvm::SmallVector<uint64_t, 64> RecordData;
     477                 : 
     478                 :   /// \brief Load the PCH file and validate its contents against the given
     479                 :   /// Preprocessor.
     480                 :   ///
     481                 :   /// \param PP the preprocessor associated with the context in which this
     482                 :   /// precompiled header will be loaded.
     483                 :   ///
     484                 :   /// \param Context the AST context that this precompiled header will be
     485                 :   /// loaded into.
     486                 :   ///
     487                 :   /// \param isysroot If non-NULL, the system include path specified by the
     488                 :   /// user. This is only used with relocatable PCH files. If non-NULL,
     489                 :   /// a relocatable PCH file will use the default path "/".
     490                 :   PCHReader(Preprocessor &PP, ASTContext *Context, const char *isysroot = 0);
     491                 : 
     492                 :   /// \brief Load the PCH file without using any pre-initialized Preprocessor.
     493                 :   ///
     494                 :   /// The necessary information to initialize a Preprocessor later can be
     495                 :   /// obtained by setting a PCHReaderListener.
     496                 :   ///
     497                 :   /// \param SourceMgr the source manager into which the precompiled header
     498                 :   /// will be loaded.
     499                 :   ///
     500                 :   /// \param FileMgr the file manager into which the precompiled header will
     501                 :   /// be loaded.
     502                 :   ///
     503                 :   /// \param Diags the diagnostics system to use for reporting errors and
     504                 :   /// warnings relevant to loading the precompiled header.
     505                 :   ///
     506                 :   /// \param isysroot If non-NULL, the system include path specified by the
     507                 :   /// user. This is only used with relocatable PCH files. If non-NULL,
     508                 :   /// a relocatable PCH file will use the default path "/".
     509                 :   PCHReader(SourceManager &SourceMgr, FileManager &FileMgr,
     510                 :             Diagnostic &Diags, const char *isysroot = 0);
     511                 :   ~PCHReader();
     512                 : 
     513                 :   /// \brief Load the precompiled header designated by the given file
     514                 :   /// name.
     515                 :   PCHReadResult ReadPCH(const std::string &FileName);
     516                 : 
     517                 :   /// \brief Set the PCH callbacks listener.
     518               13:   void setListener(PCHReaderListener *listener) {
     519               13:     Listener.reset(listener);
     520               13:   }
     521                 : 
     522                 :   /// \brief Set the Preprocessor to use.
     523               13:   void setPreprocessor(Preprocessor &pp) {
     524               13:     PP = &pp;
     525               13:   }
     526                 : 
     527                 :   /// \brief Sets and initializes the given Context.
     528                 :   void InitializeContext(ASTContext &Context);
     529                 : 
     530                 :   /// \brief Retrieve the name of the PCH file
     531                1:   const std::string &getFileName() { return FileName; }
     532                 : 
     533                 :   /// \brief Retrieve the name of the original source file name
     534               13:   const std::string &getOriginalSourceFile() { return OriginalFileName; }
     535                 : 
     536                 :   /// \brief Retrieve the name of the original source file name
     537                 :   /// directly from the PCH file, without actually loading the PCH
     538                 :   /// file.
     539                 :   static std::string getOriginalSourceFile(const std::string &PCHFileName,
     540                 :                                            Diagnostic &Diags);
     541                 : 
     542                 :   /// \brief Returns the suggested contents of the predefines buffer,
     543                 :   /// which contains a (typically-empty) subset of the predefines
     544                 :   /// build prior to including the precompiled header.
     545               46:   const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
     546                 : 
     547                 :   /// \brief Reads the source ranges that correspond to comments from
     548                 :   /// an external AST source.
     549                 :   ///
     550                 :   /// \param Comments the contents of this vector will be
     551                 :   /// replaced with the sorted set of source ranges corresponding to
     552                 :   /// comments in the source code.
     553                 :   virtual void ReadComments(std::vector<SourceRange> &Comments);
     554                 : 
     555                 :   /// \brief Reads a TemplateArgumentLocInfo appropriate for the
     556                 :   /// given TemplateArgument kind.
     557                 :   TemplateArgumentLocInfo
     558                 :   GetTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind,
     559                 :                              const RecordData &Record, unsigned &Idx);
     560                 : 
     561                 :   /// \brief Reads a declarator info from the given record.
     562                 :   virtual TypeSourceInfo *GetTypeSourceInfo(const RecordData &Record,
     563                 :                                             unsigned &Idx);
     564                 : 
     565                 :   /// \brief Resolve a type ID into a type, potentially building a new
     566                 :   /// type.
     567                 :   virtual QualType GetType(pch::TypeID ID);
     568                 : 
     569                 :   /// \brief Resolve a declaration ID into a declaration, potentially
     570                 :   /// building a new declaration.
     571                 :   virtual Decl *GetDecl(pch::DeclID ID);
     572                 : 
     573                 :   /// \brief Resolve the offset of a statement into a statement.
     574                 :   ///
     575                 :   /// This operation will read a new statement from the external
     576                 :   /// source each time it is called, and is meant to be used via a
     577                 :   /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
     578                 :   virtual Stmt *GetDeclStmt(uint64_t Offset);
     579                 : 
     580                 :   /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
     581                 :   /// specified cursor.  Read the abbreviations that are at the top of the block
     582                 :   /// and then leave the cursor pointing into the block.
     583                 :   bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
     584                 : 
     585                 :   /// \brief Read all of the declarations lexically stored in a
     586                 :   /// declaration context.
     587                 :   ///
     588                 :   /// \param DC The declaration context whose declarations will be
     589                 :   /// read.
     590                 :   ///
     591                 :   /// \param Decls Vector that will contain the declarations loaded
     592                 :   /// from the external source. The caller is responsible for merging
     593                 :   /// these declarations with any declarations already stored in the
     594                 :   /// declaration context.
     595                 :   ///
     596                 :   /// \returns true if there was an error while reading the
     597                 :   /// declarations for this declaration context.
     598                 :   virtual bool ReadDeclsLexicallyInContext(DeclContext *DC,
     599                 :                                  llvm::SmallVectorImpl<pch::DeclID> &Decls);
     600                 : 
     601                 :   /// \brief Read all of the declarations visible from a declaration
     602                 :   /// context.
     603                 :   ///
     604                 :   /// \param DC The declaration context whose visible declarations
     605                 :   /// will be read.
     606                 :   ///
     607                 :   /// \param Decls A vector of visible declaration structures,
     608                 :   /// providing the mapping from each name visible in the declaration
     609                 :   /// context to the declaration IDs of declarations with that name.
     610                 :   ///
     611                 :   /// \returns true if there was an error while reading the
     612                 :   /// declarations for this declaration context.
     613                 :   ///
     614                 :   /// FIXME: Using this intermediate data structure results in an
     615                 :   /// extraneous copying of the data. Could we pass in a reference to
     616                 :   /// the StoredDeclsMap instead?
     617                 :   virtual bool ReadDeclsVisibleInContext(DeclContext *DC,
     618                 :                        llvm::SmallVectorImpl<VisibleDeclaration> & Decls);
     619                 : 
     620                 :   /// \brief Function that will be invoked when we begin parsing a new
     621                 :   /// translation unit involving this external AST source.
     622                 :   ///
     623                 :   /// This function will provide all of the external definitions to
     624                 :   /// the ASTConsumer.
     625                 :   virtual void StartTranslationUnit(ASTConsumer *Consumer);
     626                 : 
     627                 :   /// \brief Print some statistics about PCH usage.
     628                 :   virtual void PrintStats();
     629                 : 
     630                 :   /// \brief Initialize the semantic source with the Sema instance
     631                 :   /// being used to perform semantic analysis on the abstract syntax
     632                 :   /// tree.
     633                 :   virtual void InitializeSema(Sema &S);
     634                 : 
     635                 :   /// \brief Inform the semantic consumer that Sema is no longer available.
     636               35:   virtual void ForgetSema() { SemaObj = 0; }
     637                 : 
     638                 :   /// \brief Retrieve the IdentifierInfo for the named identifier.
     639                 :   ///
     640                 :   /// This routine builds a new IdentifierInfo for the given identifier. If any
     641                 :   /// declarations with this name are visible from translation unit scope, their
     642                 :   /// declarations will be deserialized and introduced into the declaration
     643                 :   /// chain of the identifier.
     644                 :   virtual IdentifierInfo* get(const char *NameStart, const char *NameEnd);
     645                4:   IdentifierInfo* get(llvm::StringRef Name) {
     646                4:     return get(Name.begin(), Name.end());
     647                 :   }
     648                 : 
     649                 :   /// \brief Load the contents of the global method pool for a given
     650                 :   /// selector.
     651                 :   ///
     652                 :   /// \returns a pair of Objective-C methods lists containing the
     653                 :   /// instance and factory methods, respectively, with this selector.
     654                 :   virtual std::pair<ObjCMethodList, ObjCMethodList>
     655                 :     ReadMethodPool(Selector Sel);
     656                 : 
     657                 :   void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
     658                 :   void SetGloballyVisibleDecls(IdentifierInfo *II,
     659                 :                                const llvm::SmallVectorImpl<uint32_t> &DeclIDs,
     660                 :                                bool Nonrecursive = false);
     661                 : 
     662                 :   /// \brief Report a diagnostic.
     663                 :   DiagnosticBuilder Diag(unsigned DiagID);
     664                 : 
     665                 :   /// \brief Report a diagnostic.
     666                 :   DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
     667                 : 
     668                 :   IdentifierInfo *DecodeIdentifierInfo(unsigned Idx);
     669                 : 
     670              459:   IdentifierInfo *GetIdentifierInfo(const RecordData &Record, unsigned &Idx) {
     671              459:     return DecodeIdentifierInfo(Record[Idx++]);
     672                 :   }
     673                 : 
     674                1:   virtual IdentifierInfo *GetIdentifier(unsigned ID) {
     675                1:     return DecodeIdentifierInfo(ID);
     676                 :   }
     677                 : 
     678                 :   /// \brief Read the source location entry with index ID.
     679                 :   virtual void ReadSLocEntry(unsigned ID);
     680                 : 
     681                 :   Selector DecodeSelector(unsigned Idx);
     682                 : 
     683               51:   Selector GetSelector(const RecordData &Record, unsigned &Idx) {
     684               51:     return DecodeSelector(Record[Idx++]);
     685                 :   }
     686                 :   DeclarationName ReadDeclarationName(const RecordData &Record, unsigned &Idx);
     687                 : 
     688                 :   /// \brief Read an integral value
     689                 :   llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
     690                 : 
     691                 :   /// \brief Read a signed integral value
     692                 :   llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
     693                 : 
     694                 :   /// \brief Read a floating-point value
     695                 :   llvm::APFloat ReadAPFloat(const RecordData &Record, unsigned &Idx);
     696                 : 
     697                 :   // \brief Read a string
     698                 :   std::string ReadString(const RecordData &Record, unsigned &Idx);
     699                 : 
     700                 :   /// \brief Reads attributes from the current stream position.
     701                 :   Attr *ReadAttributes();
     702                 : 
     703                 :   /// \brief ReadDeclExpr - Reads an expression from the current decl cursor.
     704                 :   Expr *ReadDeclExpr();
     705                 : 
     706                 :   /// \brief ReadTypeExpr - Reads an expression from the current type cursor.
     707                 :   Expr *ReadTypeExpr();
     708                 : 
     709                 :   /// \brief Reads a statement from the specified cursor.
     710                 :   Stmt *ReadStmt(llvm::BitstreamCursor &Cursor);
     711                 : 
     712                 :   /// \brief Read a statement from the current DeclCursor.
     713                2:   Stmt *ReadDeclStmt() {
     714                2:     return ReadStmt(DeclsCursor);
     715                 :   }
     716                 : 
     717                 :   /// \brief Reads the macro record located at the given offset.
     718                 :   void ReadMacroRecord(uint64_t Offset);
     719                 : 
     720                 :   /// \brief Read the set of macros defined by this external macro source.
     721                 :   virtual void ReadDefinedMacros();
     722                 : 
     723                 :   /// \brief Retrieve the AST context that this PCH reader
     724                 :   /// supplements.
     725             2584:   ASTContext *getContext() { return Context; }
     726                 : 
     727                 :   // \brief Contains declarations that were loaded before we have
     728                 :   // access to a Sema object.
     729                 :   llvm::SmallVector<NamedDecl *, 16> PreloadedDecls;
     730                 : 
     731                 :   /// \brief Retrieve the semantic analysis object used to analyze the
     732                 :   /// translation unit in which the precompiled header is being
     733                 :   /// imported.
     734                 :   Sema *getSema() { return SemaObj; }
     735                 : 
     736                 :   /// \brief Retrieve the stream that this PCH reader is reading from.
     737                 :   llvm::BitstreamCursor &getStream() { return Stream; }
     738               26:   llvm::BitstreamCursor &getDeclsCursor() { return DeclsCursor; }
     739                 : 
     740                 :   /// \brief Retrieve the identifier table associated with the
     741                 :   /// preprocessor.
     742                 :   IdentifierTable &getIdentifierTable();
     743                 : 
     744                 :   /// \brief Record that the given ID maps to the given switch-case
     745                 :   /// statement.
     746                 :   void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
     747                 : 
     748                 :   /// \brief Retrieve the switch-case statement with the given ID.
     749                 :   SwitchCase *getSwitchCaseWithID(unsigned ID);
     750                 : 
     751                 :   /// \brief Record that the given label statement has been
     752                 :   /// deserialized and has the given ID.
     753                 :   void RecordLabelStmt(LabelStmt *S, unsigned ID);
     754                 : 
     755                 :   /// \brief Set the label of the given statement to the label
     756                 :   /// identified by ID.
     757                 :   ///
     758                 :   /// Depending on the order in which the label and other statements
     759                 :   /// referencing that label occur, this operation may complete
     760                 :   /// immediately (updating the statement) or it may queue the
     761                 :   /// statement to be back-patched later.
     762                 :   void SetLabelOf(GotoStmt *S, unsigned ID);
     763                 : 
     764                 :   /// \brief Set the label of the given expression to the label
     765                 :   /// identified by ID.
     766                 :   ///
     767                 :   /// Depending on the order in which the label and other statements
     768                 :   /// referencing that label occur, this operation may complete
     769                 :   /// immediately (updating the statement) or it may queue the
     770                 :   /// statement to be back-patched later.
     771                 :   void SetLabelOf(AddrLabelExpr *S, unsigned ID);
     772                 : };
     773                 : 
     774                 : /// \brief Helper class that saves the current stream position and
     775                 : /// then restores it when destroyed.
     776                 : struct SavedStreamPosition {
     777             1262:   explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
     778             1262:   : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { }
     779                 : 
     780             1262:   ~SavedStreamPosition() {
     781             1262:     Cursor.JumpToBit(Offset);
     782             1262:   }
     783                 : 
     784                 : private:
     785                 :   llvm::BitstreamCursor &Cursor;
     786                 :   uint64_t Offset;
     787                 : };
     788                 : 
     789                 : } // end namespace clang
     790                 : 
     791                 : #endif

Generated: 2010-02-10 01:31 by zcov