本文整理汇总了C++中iface::displayer类的典型用法代码示例。如果您正苦于以下问题:C++ displayer类的具体用法?C++ displayer怎么用?C++ displayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了displayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void pragma_environment_save::run(const data::command::iterator&,
const data::command::iterator&,
const data::command::iterator& args_begin_,
const data::command::iterator& args_end_,
iface::displayer& displayer_) const
{
if (_config.saving_enabled)
{
const std::string fn =
boost::algorithm::trim_copy(tokens_to_string(args_begin_, args_end_));
if (fn.empty())
{
displayer_.show_error(
"Filename to save the environment into is missing.");
}
else
{
std::ofstream f(fn.c_str());
f << _env.get_all() << std::endl;
if (f.fail() || f.bad())
{
displayer_.show_error("Failed to save the environment into file " + fn);
}
}
}
else
{
displayer_.show_error(
"Saving is disabled by the --disable_saving command line argument.");
}
}
示例2: run
void pragma_switch::run(const data::command::iterator&,
const data::command::iterator&,
const data::command::iterator& args_begin_,
const data::command::iterator& args_end_,
iface::displayer& displayer_) const
{
auto i = args_begin_;
if (i != args_end_)
{
const std::string v = i->value().value();
if (valid_argument(v))
{
++i;
if (i == args_end_)
{
_update(element_of(true_values, v));
}
else
{
displayer_.show_error("Invalid arguments after " + v + ": " +
tokens_to_string(i, args_end_).value());
}
}
else
{
displayer_.show_error("Invalid argument " + v + ". Valid values are: " +
valid_arguments());
}
}
displayer_.show_comment(
data::text(_name + " is " + (_query() ? "on" : "off")));
}
示例3: line_available
void mdb_shell::line_available(const std::string& line_arg,
iface::displayer& displayer_,
iface::history& history_)
{
try
{
using boost::algorithm::all;
using boost::is_space;
std::string line = line_arg;
if (line != prev_line && !line.empty())
{
history_.add(line);
}
if (line.empty())
{
if (!last_command_repeatable)
{
return;
}
line = prev_line;
}
else
{
prev_line = line;
}
if (all(line, is_space()))
{
return;
}
auto command_arg_pair = command_handler.get_command_for_line(line);
if (!command_arg_pair)
{
displayer_.show_error("Command parsing failed\n");
last_command_repeatable = false;
return;
}
mdb_command cmd;
std::string args;
std::tie(cmd, args) = *command_arg_pair;
last_command_repeatable = cmd.is_repeatable();
cmd.get_func()(*this, args, displayer_);
}
catch (const std::exception& ex)
{
displayer_.show_error(std::string("Error: ") + ex.what() + "\n");
}
catch (...)
{
displayer_.show_error("Unknown error\n");
}
}
示例4: run
void pragma_environment_add::run(
const data::command::iterator& args_begin_,
const data::command::iterator& args_end_,
iface::displayer& displayer_
) const
{
const std::string cmd = tokens_to_string(args_begin_, args_end_);
_shell.store_in_buffer(cmd, displayer_);
if (is_environment_setup_command(args_begin_, args_end_))
{
displayer_.show_comment(
data::text(
"You don't need the environment add pragma to add this to the"
" environment. The following command does this as well:"
)
);
displayer_.show_cpp_code(cmd);
}
else
{
displayer_.show_comment(
data::text(
"Metashell (incorrectly) thinks that this command should execute a"
" metaprogram and would not add it to the environment without using"
" the \"environment add\" pragma. Please file a bug report containing"
" this command (" + cmd + ") at"
" https://github.com/sabel83/metashell/issues. Thank you."
)
);
}
}
示例5: if
data::type_or_error
mdb_shell::run_metaprogram(const boost::optional<std::string>& expression,
const boost::filesystem::path& output_path_,
iface::displayer& displayer_)
{
const data::result res = _engine.eval(
env, expression, output_path_, conf.use_precompiled_headers);
if (!res.info.empty())
{
displayer_.show_raw_text(res.info);
}
if (!res.successful)
{
return data::type_or_error::make_error(res.error);
}
else if (expression)
{
return data::type_or_error::make_type(data::type(res.output));
}
else
{
return data::type_or_error::make_none();
}
}
示例6: exception
std::unique_ptr<iface::event_data_sequence> metaprogram_tracer_clang::eval(
iface::environment& env_,
const boost::filesystem::path&,
const boost::optional<data::cpp_code>& expression_,
data::metaprogram_mode mode_,
iface::displayer& displayer_)
{
const auto out = eval_with_templight_dump_on_stdout(
env_, expression_, boost::none, _clang_binary);
const data::result& res = std::get<0>(out);
const std::string& trace = std::get<1>(out);
if (!res.info.empty())
{
displayer_.show_raw_text(res.info);
}
if (trace.empty())
{
throw exception(res.successful ? "Failed to get template trace" :
res.error);
}
else
{
return filter_events(
yaml_trace(
trace, type_or_code_or_error_from_result(res, expression_),
expression_ ? *expression_ : data::cpp_code("<environment>"),
mode_),
determine_from_line(
env_.get(), expression_, data::stdin_name_in_clang()));
}
}
示例7:
void
mdb_shell::display_current_forwardtrace(boost::optional<int> max_depth,
iface::displayer& displayer_) const
{
displayer_.show_call_graph(boost::make_iterator_range(
forward_trace_iterator(*mp, max_depth), forward_trace_iterator()));
}
示例8: command_frame
void mdb_shell::command_frame(const std::string& arg,
iface::displayer& displayer_)
{
if (!require_running_or_errored_metaprogram(displayer_))
{
return;
}
const auto frame_index = parse_mandatory_integer(arg);
if (!frame_index)
{
display_argument_parsing_failed(displayer_);
return;
}
auto backtrace = mp->get_backtrace();
if (frame_index < 0 || *frame_index >= static_cast<int>(backtrace.size()))
{
displayer_.show_error("Frame index out of range");
return;
}
display_frame(backtrace[*frame_index], displayer_);
}
示例9: command_continue
void mdb_shell::command_continue(const std::string& arg,
iface::displayer& displayer_)
{
if (!require_evaluated_metaprogram(displayer_))
{
return;
}
const auto continue_count = parse_defaultable_integer(arg, 1);
if (!continue_count)
{
display_argument_parsing_failed(displayer_);
return;
}
direction_t direction =
*continue_count >= 0 ? direction_t::forward : direction_t::backwards;
const breakpoint* breakpoint_ptr = nullptr;
for (int i = 0;
i < std::abs(*continue_count) && !mp->is_at_endpoint(direction); ++i)
{
breakpoint_ptr = continue_metaprogram(direction);
}
if (breakpoint_ptr)
{
displayer_.show_raw_text(breakpoint_ptr->to_string() + " reached");
}
display_movement_info(*continue_count != 0, displayer_);
}
示例10: run_metaprogram_with_templight
bool mdb_shell::run_metaprogram_with_templight(
const boost::optional<std::string>& expression,
metaprogram::mode_t mode,
iface::displayer& displayer_)
{
const boost::filesystem::path output_path = _mdb_temp_dir / "templight.pb";
data::type_or_error evaluation_result =
run_metaprogram(expression, output_path, displayer_);
// Opening in binary mode, because some platforms interpret some characters
// specially in text mode, which caused parsing to fail.
std::ifstream protobuf_stream(output_path.string() + ".trace.pbf",
std::ios_base::in | std::ios_base::binary);
if (!protobuf_stream)
{
if (evaluation_result.is_error())
{
displayer_.show_error(evaluation_result.get_error());
}
else
{
// Shouldn't happen
displayer_.show_error("Unexpected type type_or_error result");
}
mp = boost::none;
return false;
}
mp = metaprogram::create_from_protobuf_stream(
protobuf_stream, mode, expression ? *expression : "<environment>",
data::file_location{}, // TODO something sensible here?
evaluation_result);
assert(mp);
if (mp->is_empty() && evaluation_result.is_error())
{
// Most errors will cause templight to generate an empty trace
// We're only intrested in non-empty traces
displayer_.show_error(evaluation_result.get_error());
mp = boost::none;
return false;
}
return true;
}
示例11: command_rbreak
void mdb_shell::command_rbreak(const std::string& arg,
iface::displayer& displayer_)
{
if (arg.empty())
{
displayer_.show_error("Argument expected");
return;
}
if (!require_evaluated_metaprogram(displayer_))
{
return;
}
try
{
breakpoint bp{next_breakpoint_id, boost::regex(arg)};
++next_breakpoint_id;
unsigned match_count = 0;
for (metaprogram::vertex_descriptor vertex : mp->get_vertices())
{
if (bp.match(mp->get_vertex_property(vertex).type))
{
match_count += mp->get_traversal_count(vertex);
}
}
if (match_count == 0)
{
displayer_.show_raw_text("Breakpoint \"" + arg +
"\" will never stop the execution");
}
else
{
displayer_.show_raw_text(
"Breakpoint \"" + arg + "\" will stop the execution on " +
std::to_string(match_count) +
(match_count > 1 ? " locations" : " location"));
breakpoints.push_back(bp);
}
}
catch (const boost::regex_error&)
{
displayer_.show_error("\"" + arg + "\" is not a valid regex");
}
}
示例12: display_frame
void mdb_shell::display_frame(const data::frame& frame,
iface::displayer& displayer_) const
{
displayer_.show_frame(frame);
data::file_location source_location = frame.source_location();
if (source_location.name == _env_path)
{
// We don't want to show stuff from the internal header
source_location = data::file_location();
}
// TODO: we should somehow compensate the file_locations returned by
// clang for the <stdin> file. This is hard because the file clang sees
// is just two lines (an include for the PCH and the current line)
// Until this is figured out, printing file sections for <stdin> is
// turned off
// displayer_.show_file_section(source_location, env.get());
displayer_.show_file_section(source_location, "");
}
示例13: require_empty_args
bool mdb_shell::require_empty_args(const std::string& args,
iface::displayer& displayer_) const
{
if (!args.empty())
{
displayer_.show_error("This command doesn't accept arguments");
return false;
}
return true;
}
示例14: run
void pragma_config_load::run(const data::command::iterator&,
const data::command::iterator&,
const data::command::iterator& args_begin_,
const data::command::iterator& args_end_,
iface::displayer& displayer_) const
{
const data::shell_config_name name = data::shell_config_name(
tokens_to_string(args_begin_, args_end_).value());
const auto& configs = _shell.get_config().shell_configs();
const auto cfg = std::find_if(
configs.begin(), configs.end(),
[&name](const data::shell_config& cfg_) { return cfg_.name == name; });
if (cfg == configs.end())
{
throw exception("Config " + name + " not found.");
}
else
{
const auto old_config = _shell.get_config().active_shell_config().name;
_shell.get_config().activate(name);
try
{
_shell.rebuild_environment();
displayer_.show_comment(data::text("Switched to config " + name));
}
catch (const std::exception& e)
{
displayer_.show_error("Error loading config " + name + ": " + e.what());
restore_config(old_config, _shell);
}
catch (...)
{
displayer_.show_error("Error loading config " + name +
": unknown exception");
restore_config(old_config, _shell);
}
}
}
示例15: command_break
void mdb_shell::command_break(const std::string& arg,
iface::displayer& displayer_)
{
// TODO there will other more kinds of arguments here but needs a proper but
// it needs a proper command parser
if (arg != "list")
{
displayer_.show_error("Call break like this: \"break list\"");
return;
}
if (breakpoints.empty())
{
displayer_.show_raw_text("No breakpoints currently set");
return;
}
for (const breakpoint& bp : breakpoints)
{
displayer_.show_raw_text(bp.to_string());
}
}