r275653 - Reimplement ExternalSemaSource delegation in terms of

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 17 15:16:58 PDT 2016


Sigh. Fixed in r275730.

On 17 Jul 2016 10:54 a.m., "Reid Kleckner via cfe-commits" <
cfe-commits at lists.llvm.org> wrote:

> Breaks the VS 2013 build, even though we tried to check ahead of time:
> https://llvm.org/bugs/show_bug.cgi?id=28589
> http://lab.llvm.org:8011/builders/clang-x86-win2008-selfhost/builds/9110
>
> On Fri, Jul 15, 2016 at 5:35 PM, Richard Smith via cfe-commits <
> cfe-commits at lists.llvm.org> wrote:
>
>> Author: rsmith
>> Date: Fri Jul 15 19:35:14 2016
>> New Revision: 275653
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=275653&view=rev
>> Log:
>> Reimplement ExternalSemaSource delegation in terms of
>> MultiplexExternalSemaSource to remove one of the places that needs
>> updating
>> every time the ExternalSemaSource interface changes.
>>
>> Modified:
>>     cfe/trunk/lib/Frontend/ChainedIncludesSource.cpp
>>
>> Modified: cfe/trunk/lib/Frontend/ChainedIncludesSource.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ChainedIncludesSource.cpp?rev=275653&r1=275652&r2=275653&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Frontend/ChainedIncludesSource.cpp (original)
>> +++ cfe/trunk/lib/Frontend/ChainedIncludesSource.cpp Fri Jul 15 19:35:14
>> 2016
>> @@ -18,6 +18,7 @@
>>  #include "clang/Frontend/TextDiagnosticPrinter.h"
>>  #include "clang/Lex/Preprocessor.h"
>>  #include "clang/Parse/ParseAST.h"
>> +#include "clang/Sema/MultiplexExternalSemaSource.h"
>>  #include "clang/Serialization/ASTReader.h"
>>  #include "clang/Serialization/ASTWriter.h"
>>  #include "llvm/Support/MemoryBuffer.h"
>> @@ -25,51 +26,48 @@
>>  using namespace clang;
>>
>>  namespace {
>> -class ChainedIncludesSource : public ExternalSemaSource {
>> +class ChainedIncludesSourceImpl : public ExternalSemaSource {
>>  public:
>> -  ~ChainedIncludesSource() override;
>> -
>> -  ExternalSemaSource &getFinalReader() const { return *FinalReader; }
>> -
>> -  std::vector<CompilerInstance *> CIs;
>> -  IntrusiveRefCntPtr<ExternalSemaSource> FinalReader;
>> +
>> ChainedIncludesSourceImpl(std::vector<std::unique_ptr<CompilerInstance>>
>> CIs)
>> +      : CIs(std::move(CIs)) {}
>>
>>  protected:
>>
>>  //===----------------------------------------------------------------------===//
>>    // ExternalASTSource interface.
>>
>>  //===----------------------------------------------------------------------===//
>>
>> -  Decl *GetExternalDecl(uint32_t ID) override;
>> -  Selector GetExternalSelector(uint32_t ID) override;
>> -  uint32_t GetNumExternalSelectors() override;
>> -  Stmt *GetExternalDeclStmt(uint64_t Offset) override;
>> -  CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset)
>> override;
>> -  CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset)
>> override;
>> -  bool FindExternalVisibleDeclsByName(const DeclContext *DC,
>> -                                      DeclarationName Name) override;
>> -  void
>> -  FindExternalLexicalDecls(const DeclContext *DC,
>> -                           llvm::function_ref<bool(Decl::Kind)>
>> IsKindWeWant,
>> -                           SmallVectorImpl<Decl *> &Result) override;
>> -  void CompleteType(TagDecl *Tag) override;
>> -  void CompleteType(ObjCInterfaceDecl *Class) override;
>> -  void StartedDeserializing() override;
>> -  void FinishedDeserializing() override;
>> -  void StartTranslationUnit(ASTConsumer *Consumer) override;
>> -  void PrintStats() override;
>> -
>>    /// Return the amount of memory used by memory buffers, breaking down
>>    /// by heap-backed versus mmap'ed memory.
>> -  void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
>> +  void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override {
>> +    for (unsigned i = 0, e = CIs.size(); i != e; ++i) {
>> +      if (const ExternalASTSource *eSrc =
>> +          CIs[i]->getASTContext().getExternalSource()) {
>> +        eSrc->getMemoryBufferSizes(sizes);
>> +      }
>> +    }
>> +  }
>>
>> -
>> //===----------------------------------------------------------------------===//
>> -  // ExternalSemaSource interface.
>> -
>> //===----------------------------------------------------------------------===//
>> +private:
>> +  std::vector<std::unique_ptr<CompilerInstance>> CIs;
>> +};
>>
>> -  void InitializeSema(Sema &S) override;
>> -  void ForgetSema() override;
>> -  void ReadMethodPool(Selector Sel) override;
>> -  bool LookupUnqualified(LookupResult &R, Scope *S) override;
>> +/// Members of ChainedIncludesSource, factored out so we can initialize
>> +/// them before we initialize the ExternalSemaSource base class.
>> +struct ChainedIncludesSourceMembers {
>> +  ChainedIncludesSourceImpl Impl;
>> +  IntrusiveRefCntPtr<ExternalSemaSource> FinalReader;
>> +};
>> +
>> +/// Use MultiplexExternalSemaSource to dispatch all ExternalSemaSource
>> +/// calls to the final reader.
>> +class ChainedIncludesSource
>> +    : private ChainedIncludesSourceMembers,
>> +      public MultiplexExternalSemaSource {
>> +public:
>> +  ChainedIncludesSource(std::vector<std::unique_ptr<CompilerInstance>>
>> CIs,
>> +                        IntrusiveRefCntPtr<ExternalSemaSource>
>> FinalReader)
>> +      : ChainedIncludesSourceMembers{{std::move(CIs)},
>> std::move(FinalReader)},
>> +        MultiplexExternalSemaSource(Impl, *this->FinalReader) {}
>>  };
>>  }
>>
>> @@ -107,18 +105,13 @@ createASTReader(CompilerInstance &CI, St
>>    return nullptr;
>>  }
>>
>> -ChainedIncludesSource::~ChainedIncludesSource() {
>> -  for (unsigned i = 0, e = CIs.size(); i != e; ++i)
>> -    delete CIs[i];
>> -}
>> -
>>  IntrusiveRefCntPtr<ExternalSemaSource>
>> clang::createChainedIncludesSource(
>>      CompilerInstance &CI, IntrusiveRefCntPtr<ExternalSemaSource>
>> &Reader) {
>>
>>    std::vector<std::string> &includes =
>> CI.getPreprocessorOpts().ChainedIncludes;
>>    assert(!includes.empty() && "No '-chain-include' in options!");
>>
>> -  IntrusiveRefCntPtr<ChainedIncludesSource> source(new
>> ChainedIncludesSource());
>> +  std::vector<std::unique_ptr<CompilerInstance>> CIs;
>>    InputKind IK = CI.getFrontendOpts().Inputs[0].getKind();
>>
>>    SmallVector<std::unique_ptr<llvm::MemoryBuffer>, 4> SerialBufs;
>> @@ -206,7 +199,7 @@ IntrusiveRefCntPtr<ExternalSemaSource> c
>>      SerialBufs.push_back(llvm::MemoryBuffer::getMemBufferCopy(
>>          StringRef(serialAST.data(), serialAST.size())));
>>      serialAST.clear();
>> -    source->CIs.push_back(Clang.release());
>> +    CIs.push_back(std::move(Clang));
>>    }
>>
>>    assert(!SerialBufs.empty());
>> @@ -216,83 +209,6 @@ IntrusiveRefCntPtr<ExternalSemaSource> c
>>    if (!Reader)
>>      return nullptr;
>>
>> -  source->FinalReader = Reader;
>> -  return source;
>> -}
>> -
>>
>> -//===----------------------------------------------------------------------===//
>> -// 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);
>> +  return IntrusiveRefCntPtr<ChainedIncludesSource>(
>> +      new ChainedIncludesSource(std::move(CIs), Reader));
>>  }
>> -CXXBaseSpecifier *
>> -ChainedIncludesSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
>> -  return getFinalReader().GetExternalCXXBaseSpecifiers(Offset);
>> -}
>> -CXXCtorInitializer **
>> -ChainedIncludesSource::GetExternalCXXCtorInitializers(uint64_t Offset) {
>> -  return getFinalReader().GetExternalCXXCtorInitializers(Offset);
>> -}
>> -bool
>> -ChainedIncludesSource::FindExternalVisibleDeclsByName(const DeclContext
>> *DC,
>> -                                                      DeclarationName
>> Name) {
>> -  return getFinalReader().FindExternalVisibleDeclsByName(DC, Name);
>> -}
>> -void ChainedIncludesSource::FindExternalLexicalDecls(
>> -    const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)>
>> IsKindWeWant,
>> -    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();
>> -}
>> -void ChainedIncludesSource::ReadMethodPool(Selector Sel) {
>> -  getFinalReader().ReadMethodPool(Sel);
>> -}
>> -bool ChainedIncludesSource::LookupUnqualified(LookupResult &R, Scope *S)
>> {
>> -  return getFinalReader().LookupUnqualified(R, S);
>> -}
>> -
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160717/b89f4520/attachment-0001.html>


More information about the cfe-commits mailing list