2012-08-23 01:17:09 +08:00
|
|
|
//===-- OptionValueString.cpp ------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Interpreter/OptionValueString.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
#include "lldb/Core/Stream.h"
|
2012-09-01 08:38:36 +08:00
|
|
|
#include "lldb/Interpreter/Args.h"
|
2012-08-23 01:17:09 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
void
|
|
|
|
OptionValueString::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
|
|
|
|
{
|
|
|
|
if (dump_mask & eDumpOptionType)
|
|
|
|
strm.Printf ("(%s)", GetTypeAsCString ());
|
|
|
|
if (dump_mask & eDumpOptionValue)
|
|
|
|
{
|
|
|
|
if (dump_mask & eDumpOptionType)
|
|
|
|
strm.PutCString (" = ");
|
|
|
|
if (!m_current_value.empty() || m_value_was_set)
|
|
|
|
{
|
2012-09-01 08:38:36 +08:00
|
|
|
if (m_options.Test (eOptionEncodeCharacterEscapeSequences))
|
|
|
|
{
|
|
|
|
std::string expanded_escape_value;
|
|
|
|
Args::ExpandEscapedCharacters(m_current_value.c_str(), expanded_escape_value);
|
|
|
|
if (dump_mask & eDumpOptionRaw)
|
|
|
|
strm.Printf ("%s", expanded_escape_value.c_str());
|
|
|
|
else
|
|
|
|
strm.Printf ("\"%s\"", expanded_escape_value.c_str());
|
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
else
|
2012-09-01 08:38:36 +08:00
|
|
|
{
|
|
|
|
if (dump_mask & eDumpOptionRaw)
|
|
|
|
strm.Printf ("%s", m_current_value.c_str());
|
|
|
|
else
|
|
|
|
strm.Printf ("\"%s\"", m_current_value.c_str());
|
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
2015-02-20 19:14:59 +08:00
|
|
|
OptionValueString::SetValueFromString (llvm::StringRef value,
|
2012-08-23 01:17:09 +08:00
|
|
|
VarSetOperationType op)
|
|
|
|
{
|
|
|
|
Error error;
|
2013-03-06 10:19:38 +08:00
|
|
|
|
2015-02-20 19:14:59 +08:00
|
|
|
std::string value_str = value.str();
|
|
|
|
value = value.trim();
|
|
|
|
if (value.size() > 0)
|
2013-03-06 10:19:38 +08:00
|
|
|
{
|
2015-02-20 19:14:59 +08:00
|
|
|
switch (value.front())
|
2013-03-06 10:19:38 +08:00
|
|
|
{
|
|
|
|
case '"':
|
|
|
|
case '\'':
|
|
|
|
{
|
2015-02-20 19:14:59 +08:00
|
|
|
if (value.size() <= 1 || value.back() != value.front())
|
2013-03-06 10:19:38 +08:00
|
|
|
{
|
|
|
|
error.SetErrorString("mismatched quotes");
|
|
|
|
return error;
|
|
|
|
}
|
2015-05-23 03:33:54 +08:00
|
|
|
value = value.drop_front().drop_back();
|
2013-03-06 10:19:38 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-02-20 19:14:59 +08:00
|
|
|
value_str = value.str();
|
2013-03-06 10:19:38 +08:00
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case eVarSetOperationInvalid:
|
|
|
|
case eVarSetOperationInsertBefore:
|
|
|
|
case eVarSetOperationInsertAfter:
|
|
|
|
case eVarSetOperationRemove:
|
2012-12-12 06:42:19 +08:00
|
|
|
if (m_validator)
|
|
|
|
{
|
2015-02-20 19:14:59 +08:00
|
|
|
error = m_validator(value_str.c_str(),m_validator_baton);
|
2012-12-12 06:42:19 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
}
|
2015-02-20 19:14:59 +08:00
|
|
|
error = OptionValue::SetValueFromString (value, op);
|
2012-08-23 01:17:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eVarSetOperationAppend:
|
2012-12-12 06:42:19 +08:00
|
|
|
{
|
2015-01-14 05:13:08 +08:00
|
|
|
std::string new_value(m_current_value);
|
2015-02-20 19:14:59 +08:00
|
|
|
if (value.size() > 0)
|
2012-09-01 08:38:36 +08:00
|
|
|
{
|
2015-01-14 05:13:08 +08:00
|
|
|
if (m_options.Test (eOptionEncodeCharacterEscapeSequences))
|
|
|
|
{
|
|
|
|
std::string str;
|
2015-02-20 19:14:59 +08:00
|
|
|
Args::EncodeEscapeSequences (value_str.c_str(), str);
|
2015-01-14 05:13:08 +08:00
|
|
|
new_value.append(str);
|
|
|
|
}
|
|
|
|
else
|
2015-02-20 19:14:59 +08:00
|
|
|
new_value.append(value);
|
2012-09-01 08:38:36 +08:00
|
|
|
}
|
2015-01-14 05:13:08 +08:00
|
|
|
if (m_validator)
|
|
|
|
{
|
|
|
|
error = m_validator(new_value.c_str(),m_validator_baton);
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
m_current_value.assign(new_value);
|
|
|
|
NotifyValueChanged();
|
2012-09-01 08:38:36 +08:00
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eVarSetOperationClear:
|
|
|
|
Clear ();
|
2015-01-14 05:13:08 +08:00
|
|
|
NotifyValueChanged();
|
2012-08-23 01:17:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eVarSetOperationReplace:
|
|
|
|
case eVarSetOperationAssign:
|
2012-12-12 06:42:19 +08:00
|
|
|
if (m_validator)
|
|
|
|
{
|
2015-02-20 19:14:59 +08:00
|
|
|
error = m_validator(value_str.c_str(), m_validator_baton);
|
2012-12-12 06:42:19 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
m_value_was_set = true;
|
2012-09-01 08:38:36 +08:00
|
|
|
if (m_options.Test (eOptionEncodeCharacterEscapeSequences))
|
|
|
|
{
|
2015-02-20 19:14:59 +08:00
|
|
|
Args::EncodeEscapeSequences (value_str.c_str(), m_current_value);
|
2012-09-01 08:38:36 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-20 19:14:59 +08:00
|
|
|
SetCurrentValue (value_str.c_str());
|
2012-09-01 08:38:36 +08:00
|
|
|
}
|
2015-01-14 05:13:08 +08:00
|
|
|
NotifyValueChanged();
|
2012-08-23 01:17:09 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lldb::OptionValueSP
|
|
|
|
OptionValueString::DeepCopy () const
|
|
|
|
{
|
|
|
|
return OptionValueSP(new OptionValueString(*this));
|
|
|
|
}
|
2012-12-12 06:42:19 +08:00
|
|
|
|
|
|
|
Error
|
|
|
|
OptionValueString::SetCurrentValue (const char *value)
|
|
|
|
{
|
|
|
|
if (m_validator)
|
|
|
|
{
|
|
|
|
Error error(m_validator(value,m_validator_baton));
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if (value && value[0])
|
|
|
|
m_current_value.assign (value);
|
|
|
|
else
|
|
|
|
m_current_value.clear();
|
|
|
|
return Error();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
|
|
|
OptionValueString::AppendToCurrentValue (const char *value)
|
|
|
|
{
|
|
|
|
if (value && value[0])
|
|
|
|
{
|
|
|
|
if (m_validator)
|
|
|
|
{
|
|
|
|
std::string new_value(m_current_value);
|
|
|
|
new_value.append(value);
|
|
|
|
Error error(m_validator(value,m_validator_baton));
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
m_current_value.assign(new_value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_current_value.append (value);
|
|
|
|
}
|
|
|
|
return Error();
|
|
|
|
}
|