]> granicus.if.org Git - clang/commitdiff
Give every file that ASTReader loads a type: module, PCH, precompiled preamble or...
authorSebastian Redl <sebastian.redl@getdesigned.at>
Tue, 5 Oct 2010 16:15:19 +0000 (16:15 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Tue, 5 Oct 2010 16:15:19 +0000 (16:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115626 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/CompilerInstance.h
include/clang/Serialization/ASTReader.h
lib/Frontend/ASTUnit.cpp
lib/Frontend/CompilerInstance.cpp
lib/Serialization/ASTReader.cpp
lib/Serialization/ASTReaderDecl.cpp

index e1fc924dc7e718d687db431518860961baf1d219..800d5be0685c876cff9ec0eee72b7d0a9612176c 100644 (file)
@@ -534,7 +534,7 @@ public:
   createPCHExternalASTSource(llvm::StringRef Path, const std::string &Sysroot,
                              bool DisablePCHValidation,
                              Preprocessor &PP, ASTContext &Context,
-                             void *DeserializationListener);
+                             void *DeserializationListener, bool Preamble);
 
   /// Create a code completion consumer using the invocation; note that this
   /// will cause the source manager to truncate the input source file at the
index 79186c7ad75b853014554b05d48a8c065c4ff808..c5dd186ceb6f387a807b9457ac1d2207e1f64ce7 100644 (file)
@@ -170,6 +170,13 @@ class ASTReader
     public ExternalSLocEntrySource {
 public:
   enum ASTReadResult { Success, Failure, IgnorePCH };
+  /// \brief Types of AST files.
+  enum ASTFileType {
+    Module,   ///< File is a module proper.
+    PCH,      ///< File is a PCH file treated as such.
+    Preamble, ///< File is a PCH file treated as the preamble.
+    MainFile  ///< File is a PCH file treated as the actual main file.
+  };
   friend class PCHValidator;
   friend class ASTDeclReader;
   friend class ASTStmtReader;
@@ -201,11 +208,14 @@ private:
 
   /// \brief Information that is needed for every module.
   struct PerFileData {
-    PerFileData();
+    PerFileData(ASTFileType Ty);
     ~PerFileData();
 
     // === General information ===
 
+    /// \brief The type of this AST file.
+    ASTFileType Type;
+
     /// \brief The file name of the AST file.
     std::string FileName;
 
@@ -695,7 +705,7 @@ private:
 
   void MaybeAddSystemRootToFilename(std::string &Filename);
 
-  ASTReadResult ReadASTCore(llvm::StringRef FileName);
+  ASTReadResult ReadASTCore(llvm::StringRef FileName, ASTFileType Type);
   ASTReadResult ReadASTBlock(PerFileData &F);
   bool CheckPredefinesBuffers();
   bool ParseLineTable(PerFileData &F, llvm::SmallVectorImpl<uint64_t> &Record);
@@ -776,7 +786,7 @@ public:
 
   /// \brief Load the precompiled header designated by the given file
   /// name.
-  ASTReadResult ReadAST(const std::string &FileName);
+  ASTReadResult ReadAST(const std::string &FileName, ASTFileType Type);
 
   /// \brief Set the AST callbacks listener.
   void setListener(ASTReaderListener *listener) {
index 19d1690051e4479d8ed5a01037bd37ee0c16c98b..7b87d3c2687b9e3a67e10cb597a433b103ecb952 100644 (file)
@@ -479,7 +479,7 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
   Reader->setListener(new ASTInfoCollector(LangInfo, HeaderInfo, TargetTriple,
                                            Predefines, Counter));
 
-  switch (Reader->ReadAST(Filename)) {
+  switch (Reader->ReadAST(Filename, ASTReader::MainFile)) {
   case ASTReader::Success:
     break;
 
@@ -1305,10 +1305,7 @@ unsigned ASTUnit::getMaxPCHLevel() const {
   if (!getOnlyLocalDecls())
     return Decl::MaxPCHLevel;
 
-  unsigned Result = 0;
-  if (isMainFileAST() || SavedMainFileBuffer)
-    ++Result;
-  return Result;
+  return 0;
 }
 
 ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
index 212a1cf9f246c0736b7f92fa154dd67d07b5bd1e..e3eb859153792445b749deddbb07aede23c0cadc 100644 (file)
@@ -251,10 +251,12 @@ void CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path,
                                                   bool DisablePCHValidation,
                                                  void *DeserializationListener){
   llvm::OwningPtr<ExternalASTSource> Source;
+  bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0;
   Source.reset(createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot,
                                           DisablePCHValidation,
                                           getPreprocessor(), getASTContext(),
-                                          DeserializationListener));
+                                          DeserializationListener,
+                                          Preamble));
   getASTContext().setExternalSource(Source);
 }
 
@@ -264,7 +266,8 @@ CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path,
                                              bool DisablePCHValidation,
                                              Preprocessor &PP,
                                              ASTContext &Context,
-                                             void *DeserializationListener) {
+                                             void *DeserializationListener,
+                                             bool Preamble) {
   llvm::OwningPtr<ASTReader> Reader;
   Reader.reset(new ASTReader(PP, &Context,
                              Sysroot.empty() ? 0 : Sysroot.c_str(),
@@ -272,7 +275,8 @@ CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path,
 
   Reader->setDeserializationListener(
             static_cast<ASTDeserializationListener *>(DeserializationListener));
-  switch (Reader->ReadAST(Path)) {
+  switch (Reader->ReadAST(Path,
+                          Preamble ? ASTReader::Preamble : ASTReader::PCH)) {
   case ASTReader::Success:
     // Set the predefines buffer as suggested by the PCH reader. Typically, the
     // predefines buffer will be empty.
index bc898f167657c44f8d012ba1ab7e8966c787ad93..8413faa65d62575f2595dd357d9db62c884df2fa 100644 (file)
@@ -1746,8 +1746,8 @@ ASTReader::ReadASTBlock(PerFileData &F) {
         return IgnorePCH;
       }
 
-      // Load the chained file.
-      switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen))) {
+      // Load the chained file, which is always a PCH file.
+      switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) {
       case Failure: return Failure;
         // If we have to ignore the dependency, we'll have to ignore this too.
       case IgnorePCH: return IgnorePCH;
@@ -2025,8 +2025,9 @@ ASTReader::ReadASTBlock(PerFileData &F) {
   return Failure;
 }
 
-ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName) {
-  switch(ReadASTCore(FileName)) {
+ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName,
+                                            ASTFileType Type) {
+  switch(ReadASTCore(FileName, Type)) {
   case Failure: return Failure;
   case IgnorePCH: return IgnorePCH;
   case Success: break;
@@ -2124,9 +2125,10 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName) {
   return Success;
 }
 
-ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName) {
+ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName,
+                                                ASTFileType Type) {
   PerFileData *Prev = Chain.empty() ? 0 : Chain.back();
-  Chain.push_back(new PerFileData());
+  Chain.push_back(new PerFileData(Type));
   PerFileData &F = *Chain.back();
   if (Prev)
     Prev->NextInSource = &F;
@@ -4215,8 +4217,8 @@ ASTReader::~ASTReader() {
   }
 }
 
-ASTReader::PerFileData::PerFileData()
-  : SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0),
+ASTReader::PerFileData::PerFileData(ASTFileType Ty)
+  : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0),
     LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0),
     IdentifierLookupTable(0), LocalNumMacroDefinitions(0),
     MacroDefinitionOffsets(0), LocalNumSelectors(0), SelectorOffsets(0),
index 8b912efe425fde9f011b8befed9e50b9984e9654..a68f562a3f04b3b9d97acdcae34ed02a2dea7f58 100644 (file)
@@ -168,7 +168,7 @@ void ASTDeclReader::VisitDecl(Decl *D) {
   D->setImplicit(Record[Idx++]);
   D->setUsed(Record[Idx++]);
   D->setAccess((AccessSpecifier)Record[Idx++]);
-  D->setPCHLevel(Record[Idx++] + 1);
+  D->setPCHLevel(Record[Idx++] + (F.Type <= ASTReader::PCH));
 }
 
 void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {