[llvm] r264469 - [Object] Make MachOObjectFile's constructor private, provide a static create
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 28 04:50:03 PDT 2016
On 25 March 2016 at 17:59, Lang Hames via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: lhames
> Date: Fri Mar 25 16:59:14 2016
> New Revision: 264469
>
> URL: http://llvm.org/viewvc/llvm-project?rev=264469&view=rev
> Log:
> [Object] Make MachOObjectFile's constructor private, provide a static create
> method instead.
>
> This is not quite a named constructor: Construction may fail, and
> MachOObjectFiles are usually passed by unique_ptr anyway, so create
> returns an Expected<std::unique_ptr<MachOObjectFile>>.
This is awesome.
> + if (Magic == "\xFE\xED\xFA\xCE")
> + return expectedToErrorOr(
> + MachOObjectFile::create(Buffer, false, false));
> + else if (Magic == "\xCE\xFA\xED\xFE")
> + return expectedToErrorOr(
> + MachOObjectFile::create(Buffer, true, false));
> + else if (Magic == "\xFE\xED\xFA\xCF")
> + return expectedToErrorOr(
> + MachOObjectFile::create(Buffer, false, true));
> + else if (Magic == "\xCF\xFA\xED\xFE")
> + return expectedToErrorOr(
> + MachOObjectFile::create(Buffer, true, true));
> + //else
> + return object_error::parse_failed;
You don't need the "else if" now that the returns are unconditional.
Cheers,
Rafael
More information about the llvm-commits
mailing list