UserSettingsController.cpp revision 254721
155682Smarkm//====-- UserSettingsController.cpp ------------------------------*- C++ -*-===//
2233294Sstas//
3233294Sstas//                     The LLVM Compiler Infrastructure
4233294Sstas//
555682Smarkm// This file is distributed under the University of Illinois Open Source
6233294Sstas// License. See LICENSE.TXT for details.
7233294Sstas//
8233294Sstas//===----------------------------------------------------------------------===//
955682Smarkm
10233294Sstas#include "lldb/lldb-python.h"
11233294Sstas
1255682Smarkm#include <string.h>
13233294Sstas#include <algorithm>
14233294Sstas
15233294Sstas#include "lldb/Core/UserSettingsController.h"
1655682Smarkm#include "lldb/Core/Error.h"
17233294Sstas#include "lldb/Core/RegularExpression.h"
18233294Sstas#include "lldb/Core/Stream.h"
19233294Sstas#include "lldb/Core/StreamString.h"
2055682Smarkm#include "lldb/Interpreter/CommandInterpreter.h"
21233294Sstas#include "lldb/Interpreter/OptionValueString.h"
22233294Sstas
23233294Sstasusing namespace lldb;
24233294Sstasusing namespace lldb_private;
25233294Sstas
26233294Sstas
27233294Sstaslldb::OptionValueSP
28233294SstasProperties::GetPropertyValue (const ExecutionContext *exe_ctx,
29233294Sstas                              const char *path,
30233294Sstas                              bool will_modify,
31233294Sstas                              Error &error) const
3255682Smarkm{
3355682Smarkm    OptionValuePropertiesSP properties_sp (GetValueProperties ());
34233294Sstas    if (properties_sp)
3555682Smarkm        return properties_sp->GetSubValue(exe_ctx, path, will_modify, error);
36178825Sdfr    return lldb::OptionValueSP();
37178825Sdfr}
38178825Sdfr
39178825SdfrError
40178825SdfrProperties::SetPropertyValue (const ExecutionContext *exe_ctx,
41178825Sdfr                              VarSetOperationType op,
42178825Sdfr                              const char *path,
43178825Sdfr                              const char *value)
44233294Sstas{
45178825Sdfr    OptionValuePropertiesSP properties_sp (GetValueProperties ());
46233294Sstas    if (properties_sp)
47233294Sstas        return properties_sp->SetSubValue(exe_ctx, op, path, value);
48233294Sstas    Error error;
49233294Sstas    error.SetErrorString ("no properties");
50178825Sdfr    return error;
51178825Sdfr}
52178825Sdfr
53178825Sdfrvoid
54178825SdfrProperties::DumpAllPropertyValues (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
55178825Sdfr{
56178825Sdfr    OptionValuePropertiesSP properties_sp (GetValueProperties ());
57178825Sdfr    if (properties_sp)
58178825Sdfr        return properties_sp->DumpValue (exe_ctx, strm, dump_mask);
59178825Sdfr}
60178825Sdfr
61178825Sdfrvoid
62178825SdfrProperties::DumpAllDescriptions (CommandInterpreter &interpreter,
63178825Sdfr                                 Stream &strm) const
64178825Sdfr{
65233294Sstas    strm.PutCString("Top level variables:\n\n");
66178825Sdfr
67178825Sdfr    OptionValuePropertiesSP properties_sp (GetValueProperties ());
68178825Sdfr    if (properties_sp)
69178825Sdfr        return properties_sp->DumpAllDescriptions (interpreter, strm);
70178825Sdfr}
71178825Sdfr
72178825Sdfr
73178825Sdfr
74178825SdfrError
75178825SdfrProperties::DumpPropertyValue (const ExecutionContext *exe_ctx, Stream &strm, const char *property_path, uint32_t dump_mask)
76178825Sdfr{
77233294Sstas    OptionValuePropertiesSP properties_sp (GetValueProperties ());
78178825Sdfr    if (properties_sp)
79178825Sdfr    {
80178825Sdfr        return properties_sp->DumpPropertyValue (exe_ctx,
81178825Sdfr                                                 strm,
82178825Sdfr                                                 property_path,
83178825Sdfr                                                 dump_mask);
84233294Sstas    }
85233294Sstas    Error error;
86178825Sdfr    error.SetErrorString("empty property list");
87178825Sdfr    return error;
88178825Sdfr}
89178825Sdfr
90178825Sdfrsize_t
91233294SstasProperties::Apropos (const char *keyword, std::vector<const Property *> &matching_properties) const
92178825Sdfr{
93233294Sstas    OptionValuePropertiesSP properties_sp (GetValueProperties ());
94178825Sdfr    if (properties_sp)
95178825Sdfr    {
96178825Sdfr        properties_sp->Apropos (keyword, matching_properties);
97178825Sdfr    }
98178825Sdfr    return matching_properties.size();
99178825Sdfr}
100178825Sdfr
101178825Sdfr
102178825Sdfrlldb::OptionValuePropertiesSP
103178825SdfrProperties::GetSubProperty (const ExecutionContext *exe_ctx,
104233294Sstas                            const ConstString &name)
105233294Sstas{
106233294Sstas    OptionValuePropertiesSP properties_sp (GetValueProperties ());
107233294Sstas    if (properties_sp)
108233294Sstas        return properties_sp->GetSubProperty (exe_ctx, name);
109233294Sstas    return lldb::OptionValuePropertiesSP();
110233294Sstas}
111233294Sstas
11255682Smarkm