Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Expression Evaluator and Script Watches to the debugger #1

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
17 changes: 16 additions & 1 deletion core/math/expression.cpp
Original file line number Diff line number Diff line change
@@ -1940,7 +1940,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:

const Expression::InputNode *in = static_cast<const Expression::InputNode *>(p_node);
if (in->index < 0 || in->index >= p_inputs.size()) {
r_error_str = vformat(RTR("Invalid input %i (not passed) in expression"), in->index);
r_error_str = vformat(RTR("Invalid input %d (not passed) in expression"), in->index);
return true;
}
r_ret = p_inputs[in->index];
@@ -2221,6 +2221,21 @@ void Expression::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_error_text"), &Expression::get_error_text);
}

Vector<Expression::ENode *> Expression::get_nodes_by_type(const ENode::Type p_type) const {
Vector<ENode *> filtered_nodes;
ENode *node = nodes;

while (node) {
if (node->type == p_type) {
filtered_nodes.push_back(node);
}

node = node->next;
}

return filtered_nodes;
}

Expression::Expression() :
output_type(Variant::NIL),
sequenced(false),
183 changes: 93 additions & 90 deletions core/math/expression.h
Original file line number Diff line number Diff line change
@@ -110,96 +110,6 @@ class Expression : public Reference {
FUNC_MAX
};

static int get_func_argument_count(BuiltinFunc p_func);
static String get_func_name(BuiltinFunc p_func);
static void exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return, Variant::CallError &r_error, String &r_error_str);
static BuiltinFunc find_function(const String &p_string);

private:
static const char *func_name[FUNC_MAX];

struct Input {

Variant::Type type;
String name;

Input() :
type(Variant::NIL) {
}
};

Vector<Input> inputs;
Variant::Type output_type;

String expression;

bool sequenced;
int str_ofs;
bool expression_dirty;

bool _compile_expression();

enum TokenType {
TK_CURLY_BRACKET_OPEN,
TK_CURLY_BRACKET_CLOSE,
TK_BRACKET_OPEN,
TK_BRACKET_CLOSE,
TK_PARENTHESIS_OPEN,
TK_PARENTHESIS_CLOSE,
TK_IDENTIFIER,
TK_BUILTIN_FUNC,
TK_SELF,
TK_CONSTANT,
TK_BASIC_TYPE,
TK_COLON,
TK_COMMA,
TK_PERIOD,
TK_OP_IN,
TK_OP_EQUAL,
TK_OP_NOT_EQUAL,
TK_OP_LESS,
TK_OP_LESS_EQUAL,
TK_OP_GREATER,
TK_OP_GREATER_EQUAL,
TK_OP_AND,
TK_OP_OR,
TK_OP_NOT,
TK_OP_ADD,
TK_OP_SUB,
TK_OP_MUL,
TK_OP_DIV,
TK_OP_MOD,
TK_OP_SHIFT_LEFT,
TK_OP_SHIFT_RIGHT,
TK_OP_BIT_AND,
TK_OP_BIT_OR,
TK_OP_BIT_XOR,
TK_OP_BIT_INVERT,
TK_INPUT,
TK_EOF,
TK_ERROR,
TK_MAX
};

static const char *token_name[TK_MAX];
struct Token {

TokenType type;
Variant value;
};

void _set_error(const String &p_err) {
if (error_set)
return;
error_str = p_err;
error_set = true;
}

Error _get_token(Token &r_token);

String error_str;
bool error_set;

struct ENode {

enum Type {
@@ -332,6 +242,96 @@ class Expression : public Reference {
}
};

static int get_func_argument_count(BuiltinFunc p_func);
static String get_func_name(BuiltinFunc p_func);
static void exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return, Variant::CallError &r_error, String &r_error_str);
static BuiltinFunc find_function(const String &p_string);

private:
static const char *func_name[FUNC_MAX];

struct Input {

Variant::Type type;
String name;

Input() :
type(Variant::NIL) {
}
};

Vector<Input> inputs;
Variant::Type output_type;

String expression;

bool sequenced;
int str_ofs;
bool expression_dirty;

bool _compile_expression();

enum TokenType {
TK_CURLY_BRACKET_OPEN,
TK_CURLY_BRACKET_CLOSE,
TK_BRACKET_OPEN,
TK_BRACKET_CLOSE,
TK_PARENTHESIS_OPEN,
TK_PARENTHESIS_CLOSE,
TK_IDENTIFIER,
TK_BUILTIN_FUNC,
TK_SELF,
TK_CONSTANT,
TK_BASIC_TYPE,
TK_COLON,
TK_COMMA,
TK_PERIOD,
TK_OP_IN,
TK_OP_EQUAL,
TK_OP_NOT_EQUAL,
TK_OP_LESS,
TK_OP_LESS_EQUAL,
TK_OP_GREATER,
TK_OP_GREATER_EQUAL,
TK_OP_AND,
TK_OP_OR,
TK_OP_NOT,
TK_OP_ADD,
TK_OP_SUB,
TK_OP_MUL,
TK_OP_DIV,
TK_OP_MOD,
TK_OP_SHIFT_LEFT,
TK_OP_SHIFT_RIGHT,
TK_OP_BIT_AND,
TK_OP_BIT_OR,
TK_OP_BIT_XOR,
TK_OP_BIT_INVERT,
TK_INPUT,
TK_EOF,
TK_ERROR,
TK_MAX
};

static const char *token_name[TK_MAX];
struct Token {

TokenType type;
Variant value;
};

void _set_error(const String &p_err) {
if (error_set)
return;
error_str = p_err;
error_set = true;
}

Error _get_token(Token &r_token);

String error_str;
bool error_set;

template <class T>
T *alloc_node() {
T *node = memnew(T);
@@ -356,6 +356,9 @@ class Expression : public Reference {
Variant execute(Array p_inputs, Object *p_base = NULL, bool p_show_error = true);
bool has_execute_failed() const;
String get_error_text() const;
String get_source_string() const { return expression; };

Vector<ENode *> get_nodes_by_type(const ENode::Type p_type) const;

Expression();
~Expression();
3 changes: 2 additions & 1 deletion core/script_debugger_local.cpp
Original file line number Diff line number Diff line change
@@ -144,7 +144,8 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue, b
} else {

String expr = line.get_slicec(' ', 2);
String res = p_script->debug_parse_stack_level_expression(current_frame, expr);
String res;
(void)evaluate_expression(current_frame, expr, res);
print_line(res);
}

Loading