1//===-- OptionValueArch.cpp ---------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/lldb-python.h"
11
12#include "lldb/Interpreter/OptionValueArch.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
18#include "lldb/Core/State.h"
19#include "lldb/DataFormatters/FormatManager.h"
20#include "lldb/Interpreter/Args.h"
21#include "lldb/Interpreter/CommandCompletions.h"
22
23using namespace lldb;
24using namespace lldb_private;
25
26void
27OptionValueArch::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
28{
29    if (dump_mask & eDumpOptionType)
30        strm.Printf ("(%s)", GetTypeAsCString ());
31    if (dump_mask & eDumpOptionValue)
32    {
33        if (dump_mask & eDumpOptionType)
34            strm.PutCString (" = ");
35
36        if (m_current_value.IsValid())
37        {
38            const char *arch_name = m_current_value.GetArchitectureName();
39            if (arch_name)
40                strm.PutCString (arch_name);
41        }
42    }
43}
44
45Error
46OptionValueArch::SetValueFromCString (const char *value_cstr, VarSetOperationType op)
47{
48    Error error;
49    switch (op)
50    {
51    case eVarSetOperationClear:
52        Clear();
53        break;
54
55    case eVarSetOperationReplace:
56    case eVarSetOperationAssign:
57        if (value_cstr && value_cstr[0])
58        {
59            if (m_current_value.SetTriple (value_cstr))
60                m_value_was_set = true;
61            else
62                error.SetErrorStringWithFormat("unsupported architecture '%s'", value_cstr);
63        }
64        else
65        {
66            error.SetErrorString("invalid value string");
67        }
68        break;
69
70    case eVarSetOperationInsertBefore:
71    case eVarSetOperationInsertAfter:
72    case eVarSetOperationRemove:
73    case eVarSetOperationAppend:
74    case eVarSetOperationInvalid:
75        error = OptionValue::SetValueFromCString (value_cstr, op);
76        break;
77    }
78    return error;
79}
80
81lldb::OptionValueSP
82OptionValueArch::DeepCopy () const
83{
84    return OptionValueSP(new OptionValueArch(*this));
85}
86
87
88size_t
89OptionValueArch::AutoComplete (CommandInterpreter &interpreter,
90                                   const char *s,
91                                   int match_start_point,
92                                   int max_return_elements,
93                                   bool &word_complete,
94                                   StringList &matches)
95{
96    word_complete = false;
97    matches.Clear();
98    CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
99                                                         CommandCompletions::eArchitectureCompletion,
100                                                         s,
101                                                         match_start_point,
102                                                         max_return_elements,
103                                                         NULL,
104                                                         word_complete,
105                                                         matches);
106    return matches.GetSize();
107}
108
109
110
111
112