[PATCH] D99055: [llvm-objcopy] Refactor CopyConfig structure.

Alexey Lapshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 30 07:50:36 PDT 2021


avl added a comment.

> if all the config property access went through virtual functions then it could probably be done without virtual inheritance, but with virtual functions and maybe some CRTP mix-in kind of implementations, but that may not be any better

I thought about similar approach : virtual functions and maybe some CRTP mix-in kind of implementations. 
But it looked much more heavyweight(at least the implementation which I was thinking of).

  struct CopyConfig {};
  
  template < class T >
  struct BaseMixin : public T {
    virtual int getCommonOpt() = 0;
  };
  
  template < class T >
  struct ELFMixin : public T {
    virtual int getElfOpt() = 0;
  };
  
  template < class T >
  struct COFFMixin : public T {};
  
  template < class T >
  struct MachOMixin : public T {};
  
  template < class T >
  struct WasmMixin : public T {};
  
  
  struct CopyConfigELF : public BaseMixin<CopyConfig>,
                         public ELFMixin<CopyConfig> {};
  
  struct CopyConfigCOFF : public BaseMixin<CopyConfig>,
                          public COFFMixin<CopyConfig> {};
  
  struct CopyConfigMachO : public BaseMixin<CopyConfig>,
                           public MachOMixin<CopyConfig> {};
  
  struct CopyConfigWasm : public BaseMixin<CopyConfig>,
                          public WasmMixin<CopyConfig> {};
                          
  struct CopyConfigFull : public BaseMixin<CopyConfig>,
                          public ELFMixin<CopyConfig>,
                          public COFFMixin<CopyConfig>,
                          public MachOMixin<CopyConfig>,
                          public WasmOMixin<CopyConfig>
                           {}
  
  
  struct MultiFormatCopyConfig  {
  
    MultiFormatCopyConfig() : ElfProxy(Opts) {
    }
                                 
    virtual const CopyConfigELF & getELFConfig() const {
        return ElfProxy;
    }
  
    protected:
    class CopyConfigELFProxy : public CopyConfigELF{
      CopyConfigELFProxy(CopyConfigFull& Opts) : Opts(Opts){}
      int getElfOpt() override {
        return Opts.getElfOpt();
      }
       int getCommonOpt() override {
        return Opts.getCommonOpt();
       }
      CopyConfigFull& Opts;
    };
  
  
    CopyConfigFull Opts;
    CopyConfigELFProxy ElfProxy;
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99055/new/

https://reviews.llvm.org/D99055



More information about the llvm-commits mailing list