[LoongArch][Clang] Make the parameters and return value of {x,}vorn.v builti ns ...
[llvm-project.git] / lldb / source / Interpreter / OptionValueFileSpec.cpp
blob6fa6af4ace02a9bfb0546e99d22153d6aa5f57a7
1 //===-- OptionValueFileSpec.cpp -------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Interpreter/OptionValueFileSpec.h"
11 #include "lldb/DataFormatters/FormatManager.h"
12 #include "lldb/Host/FileSystem.h"
13 #include "lldb/Interpreter/CommandCompletions.h"
14 #include "lldb/Interpreter/CommandInterpreter.h"
15 #include "lldb/Utility/Args.h"
16 #include "lldb/Utility/State.h"
18 using namespace lldb;
19 using namespace lldb_private;
21 OptionValueFileSpec::OptionValueFileSpec(bool resolve) : m_resolve(resolve) {}
23 OptionValueFileSpec::OptionValueFileSpec(const FileSpec &value, bool resolve)
24 : m_current_value(value), m_default_value(value),
26 m_resolve(resolve) {}
28 OptionValueFileSpec::OptionValueFileSpec(const FileSpec &current_value,
29 const FileSpec &default_value,
30 bool resolve)
31 : m_current_value(current_value), m_default_value(default_value),
33 m_resolve(resolve) {}
35 void OptionValueFileSpec::DumpValue(const ExecutionContext *exe_ctx,
36 Stream &strm, uint32_t dump_mask) {
37 if (dump_mask & eDumpOptionType)
38 strm.Printf("(%s)", GetTypeAsCString());
39 if (dump_mask & eDumpOptionValue) {
40 if (dump_mask & eDumpOptionType)
41 strm.PutCString(" = ");
43 if (m_current_value) {
44 strm << '"' << m_current_value.GetPath().c_str() << '"';
49 Status OptionValueFileSpec::SetValueFromString(llvm::StringRef value,
50 VarSetOperationType op) {
51 Status error;
52 switch (op) {
53 case eVarSetOperationClear:
54 Clear();
55 NotifyValueChanged();
56 break;
58 case eVarSetOperationReplace:
59 case eVarSetOperationAssign:
60 if (value.size() > 0) {
61 value = value.trim("\"' \t");
62 m_value_was_set = true;
63 m_current_value.SetFile(value.str(), FileSpec::Style::native);
64 if (m_resolve)
65 FileSystem::Instance().Resolve(m_current_value);
66 m_data_sp.reset();
67 m_data_mod_time = llvm::sys::TimePoint<>();
68 NotifyValueChanged();
69 } else {
70 error = Status::FromErrorString("invalid value string");
72 break;
74 case eVarSetOperationInsertBefore:
75 case eVarSetOperationInsertAfter:
76 case eVarSetOperationRemove:
77 case eVarSetOperationAppend:
78 case eVarSetOperationInvalid:
79 error = OptionValue::SetValueFromString(value, op);
80 break;
82 return error;
85 void OptionValueFileSpec::AutoComplete(CommandInterpreter &interpreter,
86 CompletionRequest &request) {
87 lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
88 interpreter, m_completion_mask, request, nullptr);
91 const lldb::DataBufferSP &OptionValueFileSpec::GetFileContents() {
92 if (m_current_value) {
93 const auto file_mod_time = FileSystem::Instance().GetModificationTime(m_current_value);
94 if (m_data_sp && m_data_mod_time == file_mod_time)
95 return m_data_sp;
96 m_data_sp =
97 FileSystem::Instance().CreateDataBuffer(m_current_value.GetPath());
98 m_data_mod_time = file_mod_time;
100 return m_data_sp;