================ @@ -0,0 +1,50 @@ +//===-- SBFormat.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "lldb/API/SBFormat.h" +#include "Utils.h" +#include "lldb/Core/FormatEntity.h" +#include "lldb/lldb-types.h" +#include <lldb/API/SBError.h> +#include <lldb/Utility/Status.h> + +using namespace lldb; +using namespace lldb_private; + +SBFormat::SBFormat() : m_opaque_sp() {} + +SBFormat::SBFormat(const SBFormat &rhs) { + m_opaque_sp = clone(rhs.m_opaque_sp); +} + +SBFormat::~SBFormat() = default; + +SBFormat &SBFormat::operator=(const SBFormat &rhs) { + if (this != &rhs) + m_opaque_sp = clone(rhs.m_opaque_sp); + return *this; +} + +bool SBFormat::IsValid() const { return this->operator bool(); } + +SBFormat::operator bool() const { return (bool)m_opaque_sp; } + +SBFormat SBFormat::Parse(const char *format, lldb::SBError &error) { + FormatEntrySP format_entry_sp = std::make_shared<FormatEntity::Entry>(); + Status status = FormatEntity::Parse(format, *format_entry_sp); + + SBFormat sb_format; + if (status.Fail()) + error.SetError(status); + else + sb_format.m_opaque_sp = format_entry_sp; ---------------- clayborg wrote:
We probably should always set the error in case the incoming `error` is already in an error state, and we should always set or clear the m_opaque_sp if things fail? Or we can leave m_opaque_sp alone. I was thinking something like: ``` error.SetError(status); if (error.Success()) sb_format.m_opaque_sp = format_entry_sp; else sb_format.m_opaque_sp.clear(); ``` https://github.com/llvm/llvm-project/pull/71843 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits