The Battle for Wesnoth  1.15.12+dev
formula_debugger.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2018 by Yurii Chernyi <terraninfo@terraninfo.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
20 #include "gui/widgets/button.hpp"
22 #include "gui/widgets/settings.hpp"
23 #include "gui/widgets/window.hpp"
24 #include "formula/debugger.hpp"
25 #include "font/pango/escape.hpp"
26 
27 #include <functional>
28 
29 namespace gui2::dialogs
30 {
31 
32 REGISTER_DIALOG(formula_debugger)
33 
34 void formula_debugger::pre_show(window& window)
35 {
36  // stack label
37  scroll_label* stack_label
38  = find_widget<scroll_label>(&window, "stack", false, true);
39 
40  std::stringstream stack_text;
41  std::string indent = " ";
42  int c = 0;
43  for(const auto & i : fdb_.get_call_stack())
44  {
45  for(int d = 0; d < c; ++d) {
46  stack_text << indent;
47  }
48  stack_text << "#<span color=\"green\">" << i.counter()
49  << "</span>: \"<span color=\"green\">" << font::escape_text(i.name())
50  << "</span>\": (" << font::escape_text(i.str()) << ") " << std::endl;
51  ++c;
52  }
53 
54  stack_label->set_use_markup(true);
55  stack_label->set_label(stack_text.str());
57  window.keyboard_capture(stack_label);
58 
59  // execution trace label
60  scroll_label* execution_label
61  = find_widget<scroll_label>(&window, "execution", false, true);
62 
63  std::stringstream execution_text;
64  for(const auto & i : fdb_.get_execution_trace())
65  {
66  for(int d = 0; d < i.level(); ++d) {
67  execution_text << indent;
68  }
69  if(!i.evaluated()) {
70  execution_text << "#<span color=\"green\">" << i.counter()
71  << "</span>: \"<span color=\"green\">" << font::escape_text(i.name())
72  << "</span>\": (" << font::escape_text(i.str()) << ") " << std::endl;
73  } else {
74  execution_text << "#<span color=\"yellow\">" << i.counter()
75  << "</span>: \"<span color=\"yellow\">" << font::escape_text(i.name())
76  << "</span>\": (" << font::escape_text(i.str()) << ") = "
77  << "<span color=\"orange\">"
78  << font::escape_text(i.value().to_debug_string())
79  << "</span>" << std::endl;
80  }
81  }
82 
83  execution_label->set_use_markup(true);
84  execution_label->set_label(execution_text.str());
86  // state
87  std::string state_str;
88  bool is_end = false;
89  if(!fdb_.get_current_breakpoint()) {
90  state_str = "";
91  } else {
92  state_str = fdb_.get_current_breakpoint()->name();
93  if(state_str == "End") {
94  is_end = true;
95  }
96  }
97 
98  find_widget<styled_widget>(&window, "state", false).set_label(state_str);
99 
100  // callbacks
101  button& step_button = find_widget<button>(&window, "step", false);
103  step_button,
104  std::bind(&formula_debugger::callback_step_button, this));
105 
106  button& stepout_button = find_widget<button>(&window, "stepout", false);
108  stepout_button,
110 
111  button& next_button = find_widget<button>(&window, "next", false);
113  next_button,
114  std::bind(&formula_debugger::callback_next_button, this));
115 
116  button& continue_button = find_widget<button>(&window, "continue", false);
118  continue_button,
120 
121  if(is_end) {
122  step_button.set_active(false);
123  stepout_button.set_active(false);
124  next_button.set_active(false);
125  continue_button.set_active(false);
126  }
127 }
128 
130 {
133 }
134 
136 {
139 }
140 
142 {
145 }
146 
148 {
151 }
152 
153 } // namespace dialogs
virtual void set_use_markup(bool use_markup) override
See styled_widget::set_use_markup.
void add_breakpoint_step_out()
Definition: debugger.cpp:374
Formula AI debugger.
This file contains the window object, this object is a top level container which has the event manage...
This shows the debugger for the formulas.
#define d
virtual void set_label(const t_string &label) override
See styled_widget::set_label.
Go to the end position.
Definition: scrollbar.hpp:60
This file contains the settings handling of the widget library.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:171
Label showing a text.
static int indent
Definition: log.cpp:42
std::string escape_text(const std::string &text)
Escapes the pango markup characters in a text.
Definition: escape.hpp:32
std::size_t i
Definition: function.cpp:940
void scroll_vertical_scrollbar(const scrollbar_base::scroll_mode scroll)
Scrolls the vertical scrollbar.
void add_breakpoint_continue_to_end()
Definition: debugger.cpp:360
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: button.cpp:62
wfl::formula_debugger & fdb_
Simple push button.
Definition: button.hpp:35
Dialog was closed with the OK button.
Definition: retval.hpp:34
mock_char c
void set_retval(int retval)
Convenience wrapper to set the window&#39;s exit code.
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64
void add_breakpoint_step_into()
Definition: debugger.cpp:367