r249314 - [VFS] Move class out of method so it looks less like Java.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 5 14:13:02 PDT 2015


On Mon, Oct 5, 2015 at 6:55 AM, Benjamin Kramer via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: d0k
> Date: Mon Oct  5 08:55:09 2015
> New Revision: 249314
>
> URL: http://llvm.org/viewvc/llvm-project?rev=249314&view=rev
> Log:
> [VFS] Move class out of method so it looks less like Java.
>
> No functionality change.
>
> Modified:
>     cfe/trunk/lib/Basic/VirtualFileSystem.cpp
>
> Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=249314&r1=249313&r2=249314&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
> +++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Mon Oct  5 08:55:09 2015
> @@ -942,6 +942,33 @@ ErrorOr<Status> VFSFromYAML::status(cons
>    return status(Path, *Result);
>  }
>
> +namespace {
> +/// Provide a file wrapper that returns the external name when asked.
> +class NamedFileAdaptor : public File {
> +  std::unique_ptr<File> InnerFile;
> +  std::string NewName;
> +
> +public:
> +  NamedFileAdaptor(std::unique_ptr<File> InnerFile, std::string NewName)
> +      : InnerFile(std::move(InnerFile)), NewName(std::move(NewName)) {}
> +
> +  llvm::ErrorOr<Status> status() override {
> +    auto InnerStatus = InnerFile->status();
> +    if (InnerStatus)
> +      return Status::copyWithNewName(*InnerStatus, NewName);
> +    return InnerStatus.getError();
> +  }
> +  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
> +  getBuffer(const Twine &Name, int64_t FileSize = -1,
> +            bool RequiresNullTerminator = true,
> +            bool IsVolatile = false) override {
>

Why are default arguments being specified here? This is only called
virtually, right?


> +    return InnerFile->getBuffer(Name, FileSize, RequiresNullTerminator,
> +                                IsVolatile);
> +  }
> +  std::error_code close() override { return InnerFile->close(); }
> +};
> +} // end anonymous namespace
> +
>  ErrorOr<std::unique_ptr<File>> VFSFromYAML::openFileForRead(const Twine
> &Path) {
>    ErrorOr<Entry *> E = lookupPath(Path);
>    if (!E)
> @@ -955,34 +982,9 @@ ErrorOr<std::unique_ptr<File>> VFSFromYA
>    if (!Result)
>      return Result;
>
> -  if (!F->useExternalName(UseExternalNames)) {
> -    // Provide a file wrapper that returns the external name when asked.
> -    class NamedFileAdaptor : public File {
> -      std::unique_ptr<File> InnerFile;
> -      std::string NewName;
> -
> -    public:
> -      NamedFileAdaptor(std::unique_ptr<File> InnerFile, std::string
> NewName)
> -          : InnerFile(std::move(InnerFile)), NewName(std::move(NewName))
> {}
> -
> -      llvm::ErrorOr<Status> status() override {
> -        auto InnerStatus = InnerFile->status();
> -        if (InnerStatus)
> -          return Status::copyWithNewName(*InnerStatus, NewName);
> -        return InnerStatus.getError();
> -      }
> -      llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
> -      getBuffer(const Twine &Name, int64_t FileSize = -1,
> -                bool RequiresNullTerminator = true,
> -                bool IsVolatile = false) override {
> -        return InnerFile->getBuffer(Name, FileSize,
> RequiresNullTerminator,
> -                                    IsVolatile);
> -      }
> -      std::error_code close() override { return InnerFile->close(); }
> -    };
> +  if (!F->useExternalName(UseExternalNames))
>      return std::unique_ptr<File>(
>          new NamedFileAdaptor(std::move(*Result), Path.str()));
> -  }
>
>    return Result;
>  }
>
>
> _______________________________________________
> 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/20151005/2f9d6209/attachment.html>


More information about the cfe-commits mailing list