2011-04-28 06:04:39 +08:00
|
|
|
//===-- OptionGroupOutputFile.cpp -------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-05-14 04:21:08 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupOutputFile.h"
|
2011-04-28 06:04:39 +08:00
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
OptionGroupOutputFile::OptionGroupOutputFile()
|
|
|
|
: m_file(), m_append(false, false) {}
|
2011-04-28 06:04:39 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
OptionGroupOutputFile::~OptionGroupOutputFile() {}
|
2011-04-28 06:04:39 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd'
|
2014-03-18 12:43:47 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
static OptionDefinition g_option_table[] = {
|
|
|
|
{LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument,
|
|
|
|
nullptr, nullptr, 0, eArgTypeFilename,
|
|
|
|
"Specify a path for capturing command output."},
|
|
|
|
{LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND,
|
|
|
|
OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone,
|
|
|
|
"Append to the file specified with '--outfile <path>'."},
|
2011-04-28 06:04:39 +08:00
|
|
|
};
|
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
llvm::ArrayRef<OptionDefinition> OptionGroupOutputFile::GetDefinitions() {
|
2016-09-23 05:06:13 +08:00
|
|
|
return llvm::makeArrayRef(g_option_table);
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Error OptionGroupOutputFile::SetOptionValue(
|
2016-09-24 01:48:13 +08:00
|
|
|
uint32_t option_idx, llvm::StringRef option_arg,
|
2016-09-07 04:57:50 +08:00
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
Error error;
|
|
|
|
const int short_option = g_option_table[option_idx].short_option;
|
2011-04-28 06:04:39 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
switch (short_option) {
|
|
|
|
case 'o':
|
|
|
|
error = m_file.SetValueFromString(option_arg);
|
|
|
|
break;
|
2011-04-28 06:04:39 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
case SHORT_OPTION_APND:
|
|
|
|
m_append.SetCurrentValue(true);
|
|
|
|
break;
|
2011-04-28 06:04:39 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
default:
|
|
|
|
error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
|
|
|
|
break;
|
|
|
|
}
|
2011-04-28 06:04:39 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return error;
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void OptionGroupOutputFile::OptionParsingStarting(
|
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
m_file.Clear();
|
|
|
|
m_append.Clear();
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|