[cfe-commits] r146233 - in /cfe/trunk: include/clang/Frontend/ChainedIncludesSource.h include/clang/Serialization/ChainedIncludesSource.h lib/Frontend/CMakeLists.txt lib/Frontend/ChainedIncludesSource.cpp lib/Frontend/FrontendAction.cpp lib/Serialization/CMakeLists.txt lib/Serialization/ChainedIncludesSource.cpp

Chandler Carruth chandlerc at gmail.com
Thu Dec 8 17:55:54 PST 2011


Author: chandlerc
Date: Thu Dec  8 19:55:54 2011
New Revision: 146233

URL: http://llvm.org/viewvc/llvm-project?rev=146233&view=rev
Log:
Move ChainedIncludesSource into the Frontend library. This never really
belonged in the Serialization library, it's setting up a compilation,
not just deserializing.

This should fix PR11512, making Serialization actually be layered below
Frontend, a long standing layering violation in Clang.

Added:
    cfe/trunk/include/clang/Frontend/ChainedIncludesSource.h
      - copied, changed from r146230, cfe/trunk/include/clang/Serialization/ChainedIncludesSource.h
    cfe/trunk/lib/Frontend/ChainedIncludesSource.cpp
      - copied, changed from r146230, cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp
Removed:
    cfe/trunk/include/clang/Serialization/ChainedIncludesSource.h
    cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp
Modified:
    cfe/trunk/lib/Frontend/CMakeLists.txt
    cfe/trunk/lib/Frontend/FrontendAction.cpp
    cfe/trunk/lib/Serialization/CMakeLists.txt

Copied: cfe/trunk/include/clang/Frontend/ChainedIncludesSource.h (from r146230, cfe/trunk/include/clang/Serialization/ChainedIncludesSource.h)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ChainedIncludesSource.h?p2=cfe/trunk/include/clang/Frontend/ChainedIncludesSource.h&p1=cfe/trunk/include/clang/Serialization/ChainedIncludesSource.h&r1=146230&r2=146233&rev=146233&view=diff
==============================================================================
    (empty)

Removed: cfe/trunk/include/clang/Serialization/ChainedIncludesSource.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ChainedIncludesSource.h?rev=146232&view=auto
==============================================================================
--- cfe/trunk/include/clang/Serialization/ChainedIncludesSource.h (original)
+++ cfe/trunk/include/clang/Serialization/ChainedIncludesSource.h (removed)
@@ -1,75 +0,0 @@
-//===- ChainedIncludesSource.h - Chained PCHs in Memory ---------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-//  This file defines the ChainedIncludesSource class, which converts headers
-//  to chained PCHs in memory, mainly used for testing.
-//
-//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_SERIALIZATION_CHAINEDINCLUDESSOURCE_H
-#define LLVM_CLANG_SERIALIZATION_CHAINEDINCLUDESSOURCE_H
-
-#include "clang/Sema/ExternalSemaSource.h"
-#include <vector>
-
-namespace clang {
-  class CompilerInstance;
-
-class ChainedIncludesSource : public ExternalSemaSource {
-public:
-  virtual ~ChainedIncludesSource();
-
-  static ChainedIncludesSource *create(CompilerInstance &CI);
-
-private:
-  ExternalSemaSource &getFinalReader() const { return *FinalReader; }
-
-  std::vector<CompilerInstance *> CIs;
-  llvm::OwningPtr<ExternalSemaSource> FinalReader;
-
-  
-protected:
-
-//===----------------------------------------------------------------------===//
-// ExternalASTSource interface.
-//===----------------------------------------------------------------------===//
-
-  virtual Decl *GetExternalDecl(uint32_t ID);
-  virtual Selector GetExternalSelector(uint32_t ID);
-  virtual uint32_t GetNumExternalSelectors();
-  virtual Stmt *GetExternalDeclStmt(uint64_t Offset);
-  virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset);
-  virtual DeclContextLookupResult
-  FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
-  virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
-                                        bool (*isKindWeWant)(Decl::Kind),
-                                        SmallVectorImpl<Decl*> &Result);
-  virtual void CompleteType(TagDecl *Tag);
-  virtual void CompleteType(ObjCInterfaceDecl *Class);
-  virtual void StartedDeserializing();
-  virtual void FinishedDeserializing();
-  virtual void StartTranslationUnit(ASTConsumer *Consumer);
-  virtual void PrintStats();
-
-  /// Return the amount of memory used by memory buffers, breaking down
-  /// by heap-backed versus mmap'ed memory.
-  virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const;
-
-//===----------------------------------------------------------------------===//
-// ExternalSemaSource interface.
-//===----------------------------------------------------------------------===//
-
-  virtual void InitializeSema(Sema &S);
-  virtual void ForgetSema();
-  virtual std::pair<ObjCMethodList,ObjCMethodList> ReadMethodPool(Selector Sel);
-  virtual bool LookupUnqualified(LookupResult &R, Scope *S);
-};
-
-}
-
-#endif

Modified: cfe/trunk/lib/Frontend/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CMakeLists.txt?rev=146233&r1=146232&r2=146233&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CMakeLists.txt (original)
+++ cfe/trunk/lib/Frontend/CMakeLists.txt Thu Dec  8 19:55:54 2011
@@ -13,6 +13,7 @@
   ASTMerge.cpp
   ASTUnit.cpp
   CacheTokens.cpp
+  ChainedIncludesSource.cpp
   CompilerInstance.cpp
   CompilerInvocation.cpp
   CreateInvocationFromCommandLine.cpp

Copied: cfe/trunk/lib/Frontend/ChainedIncludesSource.cpp (from r146230, cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ChainedIncludesSource.cpp?p2=cfe/trunk/lib/Frontend/ChainedIncludesSource.cpp&p1=cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp&r1=146230&r2=146233&rev=146233&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp (original)
+++ cfe/trunk/lib/Frontend/ChainedIncludesSource.cpp Thu Dec  8 19:55:54 2011
@@ -12,12 +12,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang/Serialization/ChainedIncludesSource.h"
-#include "clang/Serialization/ASTReader.h"
-#include "clang/Serialization/ASTWriter.h"
+#include "clang/Frontend/ChainedIncludesSource.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Serialization/ASTReader.h"
+#include "clang/Serialization/ASTWriter.h"
 #include "clang/Parse/ParseAST.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Basic/TargetInfo.h"

Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=146233&r1=146232&r2=146233&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Thu Dec  8 19:55:54 2011
@@ -14,6 +14,7 @@
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/ChainedIncludesSource.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Frontend/FrontendPluginRegistry.h"
@@ -21,7 +22,6 @@
 #include "clang/Parse/ParseAST.h"
 #include "clang/Serialization/ASTDeserializationListener.h"
 #include "clang/Serialization/ASTReader.h"
-#include "clang/Serialization/ChainedIncludesSource.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/ErrorHandling.h"

Modified: cfe/trunk/lib/Serialization/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/CMakeLists.txt?rev=146233&r1=146232&r2=146233&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/CMakeLists.txt (original)
+++ cfe/trunk/lib/Serialization/CMakeLists.txt Thu Dec  8 19:55:54 2011
@@ -11,7 +11,6 @@
   ASTWriter.cpp
   ASTWriterDecl.cpp
   ASTWriterStmt.cpp
-  ChainedIncludesSource.cpp
   GeneratePCH.cpp
   Module.cpp
   ModuleManager.cpp

Removed: cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp?rev=146232&view=auto
==============================================================================
--- cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp (original)
+++ cfe/trunk/lib/Serialization/ChainedIncludesSource.cpp (removed)
@@ -1,240 +0,0 @@
-//===- ChainedIncludesSource.cpp - Chained PCHs in Memory -------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-//  This file defines the ChainedIncludesSource class, which converts headers
-//  to chained PCHs in memory, mainly used for testing.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Serialization/ChainedIncludesSource.h"
-#include "clang/Serialization/ASTReader.h"
-#include "clang/Serialization/ASTWriter.h"
-#include "clang/Frontend/TextDiagnosticPrinter.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/ASTUnit.h"
-#include "clang/Parse/ParseAST.h"
-#include "clang/Lex/Preprocessor.h"
-#include "clang/Basic/TargetInfo.h"
-#include "llvm/Support/MemoryBuffer.h"
-
-using namespace clang;
-
-static ASTReader *createASTReader(CompilerInstance &CI,
-                                  StringRef pchFile,  
-                                  SmallVector<llvm::MemoryBuffer *, 4> &memBufs,
-                                  SmallVector<std::string, 4> &bufNames,
-                             ASTDeserializationListener *deserialListener = 0) {
-  Preprocessor &PP = CI.getPreprocessor();
-  llvm::OwningPtr<ASTReader> Reader;
-  Reader.reset(new ASTReader(PP, CI.getASTContext(), /*isysroot=*/"",
-                             /*DisableValidation=*/true));
-  for (unsigned ti = 0; ti < bufNames.size(); ++ti) {
-    StringRef sr(bufNames[ti]);
-    Reader->addInMemoryBuffer(sr, memBufs[ti]);
-  }
-  Reader->setDeserializationListener(deserialListener);
-  switch (Reader->ReadAST(pchFile, serialization::MK_PCH)) {
-  case ASTReader::Success:
-    // Set the predefines buffer as suggested by the PCH reader.
-    PP.setPredefines(Reader->getSuggestedPredefines());
-    return Reader.take();
-
-  case ASTReader::Failure:
-  case ASTReader::IgnorePCH:
-    break;
-  }
-  return 0;
-}
-
-ChainedIncludesSource::~ChainedIncludesSource() {
-  for (unsigned i = 0, e = CIs.size(); i != e; ++i)
-    delete CIs[i];
-}
-
-ChainedIncludesSource *ChainedIncludesSource::create(CompilerInstance &CI) {
-
-  std::vector<std::string> &includes = CI.getPreprocessorOpts().ChainedIncludes;
-  assert(!includes.empty() && "No '-chain-include' in options!");
-
-  llvm::OwningPtr<ChainedIncludesSource> source(new ChainedIncludesSource());
-  InputKind IK = CI.getFrontendOpts().Inputs[0].first;
-
-  SmallVector<llvm::MemoryBuffer *, 4> serialBufs;
-  SmallVector<std::string, 4> serialBufNames;
-
-  for (unsigned i = 0, e = includes.size(); i != e; ++i) {
-    bool firstInclude = (i == 0);
-    llvm::OwningPtr<CompilerInvocation> CInvok;
-    CInvok.reset(new CompilerInvocation(CI.getInvocation()));
-    
-    CInvok->getPreprocessorOpts().ChainedIncludes.clear();
-    CInvok->getPreprocessorOpts().ImplicitPCHInclude.clear();
-    CInvok->getPreprocessorOpts().ImplicitPTHInclude.clear();
-    CInvok->getPreprocessorOpts().DisablePCHValidation = true;
-    CInvok->getPreprocessorOpts().Includes.clear();
-    CInvok->getPreprocessorOpts().MacroIncludes.clear();
-    CInvok->getPreprocessorOpts().Macros.clear();
-    
-    CInvok->getFrontendOpts().Inputs.clear();
-    CInvok->getFrontendOpts().Inputs.push_back(std::make_pair(IK, includes[i]));
-
-    TextDiagnosticPrinter *DiagClient =
-      new TextDiagnosticPrinter(llvm::errs(), DiagnosticOptions());
-    llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
-    llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
-        new DiagnosticsEngine(DiagID, DiagClient));
-
-    llvm::OwningPtr<CompilerInstance> Clang(new CompilerInstance());
-    Clang->setInvocation(CInvok.take());
-    Clang->setDiagnostics(Diags.getPtr());
-    Clang->setTarget(TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),
-                                                  Clang->getTargetOpts()));
-    Clang->createFileManager();
-    Clang->createSourceManager(Clang->getFileManager());
-    Clang->createPreprocessor();
-    Clang->getDiagnosticClient().BeginSourceFile(Clang->getLangOpts(),
-                                                 &Clang->getPreprocessor());
-    Clang->createASTContext();
-
-    SmallVector<char, 256> serialAST;
-    llvm::raw_svector_ostream OS(serialAST);
-    llvm::OwningPtr<ASTConsumer> consumer;
-    consumer.reset(new PCHGenerator(Clang->getPreprocessor(), "-", 0,
-                                    /*isysroot=*/"", &OS));
-    Clang->getASTContext().setASTMutationListener(
-                                            consumer->GetASTMutationListener());
-    Clang->setASTConsumer(consumer.take());
-    Clang->createSema(TU_Prefix, 0);
-
-    if (firstInclude) {
-      Preprocessor &PP = Clang->getPreprocessor();
-      PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(),
-                                             PP.getLangOptions());
-    } else {
-      assert(!serialBufs.empty());
-      SmallVector<llvm::MemoryBuffer *, 4> bufs;
-      for (unsigned si = 0, se = serialBufs.size(); si != se; ++si) {
-        bufs.push_back(llvm::MemoryBuffer::getMemBufferCopy(
-                             StringRef(serialBufs[si]->getBufferStart(),
-                                             serialBufs[si]->getBufferSize())));
-      }
-      std::string pchName = includes[i-1];
-      llvm::raw_string_ostream os(pchName);
-      os << ".pch" << i-1;
-      os.flush();
-      
-      serialBufNames.push_back(pchName);
-
-      llvm::OwningPtr<ExternalASTSource> Reader;
-
-      Reader.reset(createASTReader(*Clang, pchName, bufs, serialBufNames, 
-        Clang->getASTConsumer().GetASTDeserializationListener()));
-      if (!Reader)
-        return 0;
-      Clang->getASTContext().setExternalSource(Reader);
-    }
-    
-    if (!Clang->InitializeSourceManager(includes[i]))
-      return 0;
-
-    ParseAST(Clang->getSema());
-    OS.flush();
-    Clang->getDiagnosticClient().EndSourceFile();
-    serialBufs.push_back(
-      llvm::MemoryBuffer::getMemBufferCopy(StringRef(serialAST.data(),
-                                                           serialAST.size())));
-    source->CIs.push_back(Clang.take());
-  }
-
-  assert(!serialBufs.empty());
-  std::string pchName = includes.back() + ".pch-final";
-  serialBufNames.push_back(pchName);
-  llvm::OwningPtr<ASTReader> Reader;
-  Reader.reset(createASTReader(CI, pchName, serialBufs, serialBufNames));
-  if (!Reader)
-    return 0;
-
-  source->FinalReader.reset(Reader.take());
-  return source.take();
-}
-
-//===----------------------------------------------------------------------===//
-// ExternalASTSource interface.
-//===----------------------------------------------------------------------===//
-
-Decl *ChainedIncludesSource::GetExternalDecl(uint32_t ID) {
-  return getFinalReader().GetExternalDecl(ID);
-}
-Selector ChainedIncludesSource::GetExternalSelector(uint32_t ID) {
-  return getFinalReader().GetExternalSelector(ID);
-}
-uint32_t ChainedIncludesSource::GetNumExternalSelectors() {
-  return getFinalReader().GetNumExternalSelectors();
-}
-Stmt *ChainedIncludesSource::GetExternalDeclStmt(uint64_t Offset) {
-  return getFinalReader().GetExternalDeclStmt(Offset);
-}
-CXXBaseSpecifier *
-ChainedIncludesSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
-  return getFinalReader().GetExternalCXXBaseSpecifiers(Offset);
-}
-DeclContextLookupResult
-ChainedIncludesSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
-                                                      DeclarationName Name) {
-  return getFinalReader().FindExternalVisibleDeclsByName(DC, Name);
-}
-ExternalLoadResult 
-ChainedIncludesSource::FindExternalLexicalDecls(const DeclContext *DC,
-                                      bool (*isKindWeWant)(Decl::Kind),
-                                      SmallVectorImpl<Decl*> &Result) {
-  return getFinalReader().FindExternalLexicalDecls(DC, isKindWeWant, Result);
-}
-void ChainedIncludesSource::CompleteType(TagDecl *Tag) {
-  return getFinalReader().CompleteType(Tag);
-}
-void ChainedIncludesSource::CompleteType(ObjCInterfaceDecl *Class) {
-  return getFinalReader().CompleteType(Class);
-}
-void ChainedIncludesSource::StartedDeserializing() {
-  return getFinalReader().StartedDeserializing();
-}
-void ChainedIncludesSource::FinishedDeserializing() {
-  return getFinalReader().FinishedDeserializing();
-}
-void ChainedIncludesSource::StartTranslationUnit(ASTConsumer *Consumer) {
-  return getFinalReader().StartTranslationUnit(Consumer);
-}
-void ChainedIncludesSource::PrintStats() {
-  return getFinalReader().PrintStats();
-}
-void ChainedIncludesSource::getMemoryBufferSizes(MemoryBufferSizes &sizes)const{
-  for (unsigned i = 0, e = CIs.size(); i != e; ++i) {
-    if (const ExternalASTSource *eSrc =
-        CIs[i]->getASTContext().getExternalSource()) {
-      eSrc->getMemoryBufferSizes(sizes);
-    }
-  }
-
-  getFinalReader().getMemoryBufferSizes(sizes);
-}
-
-void ChainedIncludesSource::InitializeSema(Sema &S) {
-  return getFinalReader().InitializeSema(S);
-}
-void ChainedIncludesSource::ForgetSema() {
-  return getFinalReader().ForgetSema();
-}
-std::pair<ObjCMethodList,ObjCMethodList>
-ChainedIncludesSource::ReadMethodPool(Selector Sel) {
-  return getFinalReader().ReadMethodPool(Sel);
-}
-bool ChainedIncludesSource::LookupUnqualified(LookupResult &R, Scope *S) {
-  return getFinalReader().LookupUnqualified(R, S);
-}
-





More information about the cfe-commits mailing list