The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
debugger.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Yurii Chernyi <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 /**
16  * @file
17  * Formula AI debugger
18  *
19  */
20 
21 #ifndef FORMULA_DEBUGGER_HPP_INCLUDED
22 #define FORMULA_DEBUGGER_HPP_INCLUDED
23 
24 #include "global.hpp"
25 
26 #include "formula/variant.hpp"
27 #include "formula/debugger_fwd.hpp"
28 #include <deque>
29 
30 namespace game_logic {
31 
32 class formula_expression;
33 class formula_callable;
34 class formula;
35 class formula_debugger;
36 
37 class debug_info {
38 public:
39  debug_info(int arg_number, int counter, int level, const std::string &name, const std::string &str, const variant &value, bool evaluated);
40  virtual ~debug_info();
41  int counter() const;
42  int level() const;
43  const std::string& name() const;
44  const std::string& str() const;
45  const variant& value() const;
46  const std::string& value_str() const;
47  bool evaluated() const;
48  void set_evaluated(bool evaluated);
49  void set_value(const variant &value);
50 private:
52  int counter_;
53  int level_;
57  bool evaluated_;
58 
59 };
60 
62 public:
63  base_breakpoint(formula_debugger &fdb, const std::string &name, bool one_time_only);
64  virtual ~base_breakpoint();
65  virtual bool is_break_now() const = 0;
66  bool is_one_time_only() const;
67  const std::string &name() const;
68 protected:
72 
73 };
74 
75 
77 public:
79 
80 
81  virtual ~formula_debugger();
82 
83 
84  void add_debug_info(int arg_number, const std::string& f_name);
85 
86 
87  void call_stack_push(const std::string &str);
88 
89 
90  void call_stack_pop();
91 
92 
93  void call_stack_set_evaluated(bool evaluated);
94 
95 
96  void call_stack_set_value(const variant &v);
97 
98 
99  void check_breakpoints();
100 
101 
102  const std::deque<debug_info>& get_call_stack() const;
103 
104 
106 
107 
108  const std::deque<debug_info>& get_execution_trace() const;
109 
110 
111  variant evaluate_arg_callback(const formula_expression &expression, const formula_callable &variables);
112 
113 
114  variant evaluate_formula_callback(const formula &f, const formula_callable &variables);
115 
116 
118 
119 
120  void show_gui();
121 
122 
124 
125 
127 
128 
130 
131 
132  void add_breakpoint_next();
133 
134 
135  //static functions
136 
137  static formula_debugger* add_debug_info(formula_debugger *fdb, int arg_number, const std::string& f_name)
138  {
139  if (fdb==nullptr) {
140  return nullptr;
141  }
142  fdb->add_debug_info(arg_number,f_name);
143  return fdb;
144  }
145 
146 private:
147  std::deque<debug_info> call_stack_;
148  int counter_;
150  std::deque< breakpoint_ptr > breakpoints_;
151  std::deque<debug_info> execution_trace_;
154 
155 
156 };
157 
158 
159 
160 } // end of namespace game_logic
161 
162 #endif
const std::string & str() const
Definition: debugger.cpp:93
void set_evaluated(bool evaluated)
Definition: debugger.cpp:87
GLuint counter
Definition: glew.h:2584
GLint level
Definition: glew.h:1220
formula_debugger & fdb_
Definition: debugger.hpp:69
const std::string & value_str() const
std::string f_name_extra_debug_info
Definition: debugger.hpp:153
int counter() const
Definition: debugger.cpp:63
const std::string & name() const
Definition: debugger.cpp:57
Formula AI debugger, forward.
virtual bool is_break_now() const =0
const std::deque< debug_info > & get_call_stack() const
Definition: debugger.cpp:125
bool evaluated() const
Definition: debugger.cpp:81
variant evaluate_formula_callback(const formula &f, const formula_callable &variables)
Definition: debugger.cpp:211
const GLdouble * v
Definition: glew.h:1359
GLsizei const GLfloat * value
Definition: glew.h:1817
const std::string & name() const
Definition: debugger.cpp:259
void set_value(const variant &value)
Definition: debugger.cpp:75
void call_stack_push(const std::string &str)
Definition: debugger.cpp:170
const variant & value() const
Definition: debugger.cpp:69
int level() const
Definition: debugger.cpp:52
std::deque< debug_info > execution_trace_
Definition: debugger.hpp:151
base_breakpoint(formula_debugger &fdb, const std::string &name, bool one_time_only)
Definition: debugger.cpp:241
debug_info(int arg_number, int counter, int level, const std::string &name, const std::string &str, const variant &value, bool evaluated)
Definition: debugger.cpp:41
void call_stack_set_value(const variant &v)
Definition: debugger.cpp:191
static formula_debugger * add_debug_info(formula_debugger *fdb, int arg_number, const std::string &f_name)
Definition: debugger.hpp:137
variant evaluate_arg_callback(const formula_expression &expression, const formula_callable &variables)
Definition: debugger.cpp:196
GLuint const GLchar * name
Definition: glew.h:1782
std::deque< breakpoint_ptr > breakpoints_
Definition: debugger.hpp:150
const breakpoint_ptr get_current_breakpoint() const
Definition: debugger.cpp:131
void call_stack_set_evaluated(bool evaluated)
Definition: debugger.cpp:186
breakpoint_ptr current_breakpoint_
Definition: debugger.hpp:149
void add_debug_info(int arg_number, const std::string &f_name)
Definition: debugger.cpp:118
GLsizei const GLcharARB ** string
Definition: glew.h:4503
std::deque< debug_info > call_stack_
Definition: debugger.hpp:147
bool is_one_time_only() const
Definition: debugger.cpp:253
const std::deque< debug_info > & get_execution_trace() const
Definition: debugger.cpp:136
GLclampf f
Definition: glew.h:3024