1 //===-- OptionValueFileSpecList.cpp -----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Interpreter/OptionValueFileSpecList.h"
14 // Other libraries and framework includes
16 #include "lldb/Core/Stream.h"
17 #include "lldb/Interpreter/Args.h"
20 using namespace lldb_private;
23 OptionValueFileSpecList::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
25 if (dump_mask & eDumpOptionType)
26 strm.Printf ("(%s)", GetTypeAsCString ());
27 if (dump_mask & eDumpOptionValue)
29 if (dump_mask & eDumpOptionType)
30 strm.Printf (" =%s", m_current_value.GetSize() > 0 ? "\n" : "");
32 const uint32_t size = m_current_value.GetSize();
33 for (uint32_t i = 0; i<size; ++i)
36 strm.Printf("[%u]: ", i);
37 m_current_value.GetFileSpecAtIndex(i).Dump(&strm);
44 OptionValueFileSpecList::SetValueFromCString (const char *value, VarSetOperationType op)
48 const size_t argc = args.GetArgumentCount();
52 case eVarSetOperationClear:
56 case eVarSetOperationReplace:
59 uint32_t idx = Args::StringToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
60 const uint32_t count = m_current_value.GetSize();
63 error.SetErrorStringWithFormat("invalid file list index %u, index must be 0 through %u", idx, count);
67 for (size_t i=1; i<argc; ++i, ++idx)
69 FileSpec file (args.GetArgumentAtIndex(i), false);
71 m_current_value.Replace(idx, file);
73 m_current_value.Append(file);
79 error.SetErrorString("replace operation takes an array index followed by one or more values");
85 case eVarSetOperationAssign:
86 m_current_value.Clear();
87 // Fall through to append case
88 case eVarSetOperationAppend:
91 m_value_was_set = true;
92 for (size_t i=0; i<argc; ++i)
94 FileSpec file (args.GetArgumentAtIndex(i), false);
95 m_current_value.Append(file);
100 error.SetErrorString("assign operation takes at least one file path argument");
104 case eVarSetOperationInsertBefore:
105 case eVarSetOperationInsertAfter:
108 uint32_t idx = Args::StringToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
109 const uint32_t count = m_current_value.GetSize();
112 error.SetErrorStringWithFormat("invalid insert file list index %u, index must be 0 through %u", idx, count);
116 if (op == eVarSetOperationInsertAfter)
118 for (size_t i=1; i<argc; ++i, ++idx)
120 FileSpec file (args.GetArgumentAtIndex(i), false);
121 m_current_value.Insert (idx, file);
127 error.SetErrorString("insert operation takes an array index followed by one or more values");
131 case eVarSetOperationRemove:
134 std::vector<int> remove_indexes;
135 bool all_indexes_valid = true;
137 for (i=0; all_indexes_valid && i<argc; ++i)
139 const int idx = Args::StringToSInt32(args.GetArgumentAtIndex(i), INT32_MAX);
140 if (idx == INT32_MAX)
141 all_indexes_valid = false;
143 remove_indexes.push_back(idx);
146 if (all_indexes_valid)
148 size_t num_remove_indexes = remove_indexes.size();
149 if (num_remove_indexes)
151 // Sort and then erase in reverse so indexes are always valid
152 std::sort(remove_indexes.begin(), remove_indexes.end());
153 for (size_t j=num_remove_indexes-1; j<num_remove_indexes; ++j)
155 m_current_value.Remove (j);
161 error.SetErrorStringWithFormat("invalid array index '%s', aborting remove operation", args.GetArgumentAtIndex(i));
166 error.SetErrorString("remove operation takes one or more array index");
170 case eVarSetOperationInvalid:
171 error = OptionValue::SetValueFromCString (value, op);
176 m_value_was_set = true;
181 OptionValueFileSpecList::DeepCopy () const
183 return OptionValueSP(new OptionValueFileSpecList(*this));