summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/gdscript_disassembler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/gdscript_disassembler.cpp')
-rw-r--r--modules/gdscript/gdscript_disassembler.cpp132
1 files changed, 101 insertions, 31 deletions
diff --git a/modules/gdscript/gdscript_disassembler.cpp b/modules/gdscript/gdscript_disassembler.cpp
index d4f4358ac1..ec1d0af329 100644
--- a/modules/gdscript/gdscript_disassembler.cpp
+++ b/modules/gdscript/gdscript_disassembler.cpp
@@ -30,10 +30,10 @@
#ifdef DEBUG_ENABLED
+#include "gdscript.h"
#include "gdscript_function.h"
#include "core/string/string_builder.h"
-#include "gdscript.h"
static String _get_variant_string(const Variant &p_variant) {
String txt;
@@ -50,12 +50,17 @@ static String _get_variant_string(const Variant &p_variant) {
} else {
GDScriptNativeClass *cls = Object::cast_to<GDScriptNativeClass>(obj);
if (cls) {
- txt += cls->get_name();
- txt += " (class)";
+ txt = "class(" + cls->get_name() + ")";
} else {
- txt = obj->get_class();
- if (obj->get_script_instance()) {
- txt += "(" + obj->get_script_instance()->get_script()->get_path() + ")";
+ Script *script = Object::cast_to<Script>(obj);
+ if (script) {
+ txt = "script(" + GDScript::debug_get_script_name(script) + ")";
+ } else {
+ txt = "object(" + obj->get_class();
+ if (obj->get_script_instance()) {
+ txt += ", " + GDScript::debug_get_script_name(obj->get_script_instance()->get_script());
+ }
+ txt += ")";
}
}
}
@@ -69,12 +74,6 @@ static String _disassemble_address(const GDScript *p_script, const GDScriptFunct
int addr = p_address & GDScriptFunction::ADDR_MASK;
switch (p_address >> GDScriptFunction::ADDR_BITS) {
- case GDScriptFunction::ADDR_TYPE_MEMBER: {
- return "member(" + p_script->debug_get_member_by_index(addr) + ")";
- } break;
- case GDScriptFunction::ADDR_TYPE_CONSTANT: {
- return "const(" + _get_variant_string(p_function.get_constant(addr)) + ")";
- } break;
case GDScriptFunction::ADDR_TYPE_STACK: {
switch (addr) {
case GDScriptFunction::ADDR_STACK_SELF:
@@ -87,6 +86,12 @@ static String _disassemble_address(const GDScript *p_script, const GDScriptFunct
return "stack(" + itos(addr) + ")";
}
} break;
+ case GDScriptFunction::ADDR_TYPE_CONSTANT: {
+ return "const(" + _get_variant_string(p_function.get_constant(addr)) + ")";
+ } break;
+ case GDScriptFunction::ADDR_TYPE_MEMBER: {
+ return "member(" + p_script->debug_get_member_by_index(addr) + ")";
+ } break;
}
return "<err>";
@@ -135,23 +140,58 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr += 5;
} break;
- case OPCODE_EXTENDS_TEST: {
- text += "is object ";
- text += DADDR(3);
- text += " = ";
+ case OPCODE_TYPE_TEST_BUILTIN: {
+ text += "type test ";
text += DADDR(1);
- text += " is ";
+ text += " = ";
text += DADDR(2);
+ text += " is ";
+ text += Variant::get_type_name(Variant::Type(_code_ptr[ip + 3]));
incr += 4;
} break;
- case OPCODE_IS_BUILTIN: {
- text += "is builtin ";
+ case OPCODE_TYPE_TEST_ARRAY: {
+ text += "type test ";
+ text += DADDR(1);
+ text += " = ";
text += DADDR(2);
+ text += " is Array[";
+
+ Ref<Script> script_type = get_constant(_code_ptr[ip + 3] & ADDR_MASK);
+ Variant::Type builtin_type = (Variant::Type)_code_ptr[ip + 4];
+ StringName native_type = get_global_name(_code_ptr[ip + 5]);
+
+ if (script_type.is_valid() && script_type->is_valid()) {
+ text += "script(";
+ text += GDScript::debug_get_script_name(script_type);
+ text += ")";
+ } else if (native_type != StringName()) {
+ text += native_type;
+ } else {
+ text += Variant::get_type_name(builtin_type);
+ }
+
+ text += "]";
+
+ incr += 6;
+ } break;
+ case OPCODE_TYPE_TEST_NATIVE: {
+ text += "type test ";
+ text += DADDR(1);
text += " = ";
+ text += DADDR(2);
+ text += " is ";
+ text += get_global_name(_code_ptr[ip + 3]);
+
+ incr += 4;
+ } break;
+ case OPCODE_TYPE_TEST_SCRIPT: {
+ text += "type test ";
text += DADDR(1);
+ text += " = ";
+ text += DADDR(2);
text += " is ";
- text += Variant::get_type_name(Variant::Type(_code_ptr[ip + 3]));
+ text += DADDR(3);
incr += 4;
} break;
@@ -279,6 +319,38 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr += 3;
} break;
+ case OPCODE_SET_STATIC_VARIABLE: {
+ Ref<GDScript> gdscript = get_constant(_code_ptr[ip + 2] & ADDR_MASK);
+
+ text += "set_static_variable script(";
+ text += GDScript::debug_get_script_name(gdscript);
+ text += ")";
+ if (gdscript.is_valid()) {
+ text += "[\"" + gdscript->debug_get_static_var_by_index(_code_ptr[ip + 3]) + "\"]";
+ } else {
+ text += "[<index " + itos(_code_ptr[ip + 3]) + ">]";
+ }
+ text += " = ";
+ text += DADDR(1);
+
+ incr += 4;
+ } break;
+ case OPCODE_GET_STATIC_VARIABLE: {
+ Ref<GDScript> gdscript = get_constant(_code_ptr[ip + 2] & ADDR_MASK);
+
+ text += "get_static_variable ";
+ text += DADDR(1);
+ text += " = script(";
+ text += GDScript::debug_get_script_name(gdscript);
+ text += ")";
+ if (gdscript.is_valid()) {
+ text += "[\"" + gdscript->debug_get_static_var_by_index(_code_ptr[ip + 3]) + "\"]";
+ } else {
+ text += "[<index " + itos(_code_ptr[ip + 3]) + ">]";
+ }
+
+ incr += 4;
+ } break;
case OPCODE_ASSIGN: {
text += "assign ";
text += DADDR(1);
@@ -330,11 +402,10 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr += 4;
} break;
case OPCODE_ASSIGN_TYPED_SCRIPT: {
- Variant script = _constants_ptr[_code_ptr[ip + 3]];
- Script *sc = Object::cast_to<Script>(script.operator Object *());
+ Ref<Script> script = get_constant(_code_ptr[ip + 3] & ADDR_MASK);
text += "assign typed script (";
- text += sc->get_path();
+ text += GDScript::debug_get_script_name(script);
text += ") ";
text += DADDR(1);
text += " = ";
@@ -434,13 +505,13 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
int instr_var_args = _code_ptr[++ip];
int argc = _code_ptr[ip + 1 + instr_var_args];
- Ref<Script> script_type = get_constant(_code_ptr[ip + argc + 2] & GDScriptFunction::ADDR_MASK);
+ Ref<Script> script_type = get_constant(_code_ptr[ip + argc + 2] & ADDR_MASK);
Variant::Type builtin_type = (Variant::Type)_code_ptr[ip + argc + 4];
StringName native_type = get_global_name(_code_ptr[ip + argc + 5]);
String type_name;
if (script_type.is_valid() && script_type->is_valid()) {
- type_name = script_type->get_path();
+ type_name = "script(" + GDScript::debug_get_script_name(script_type) + ")";
} else if (native_type != StringName()) {
type_name = native_type;
} else {
@@ -818,7 +889,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
}
text += ")";
- incr = 3 + captures_count;
+ incr = 4 + captures_count;
} break;
case OPCODE_CREATE_SELF_LAMBDA: {
int instr_var_args = _code_ptr[++ip];
@@ -838,7 +909,7 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
}
text += ")";
- incr = 3 + captures_count;
+ incr = 4 + captures_count;
} break;
case OPCODE_JUMP: {
text += "jump ";
@@ -904,11 +975,10 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
incr += 3;
} break;
case OPCODE_RETURN_TYPED_SCRIPT: {
- Variant script = _constants_ptr[_code_ptr[ip + 2]];
- Script *sc = Object::cast_to<Script>(script.operator Object *());
+ Ref<Script> script = get_constant(_code_ptr[ip + 2] & ADDR_MASK);
text += "return typed script (";
- text += sc->get_path();
+ text += GDScript::debug_get_script_name(script);
text += ") ";
text += DADDR(1);
@@ -1097,4 +1167,4 @@ void GDScriptFunction::disassemble(const Vector<String> &p_code_lines) const {
}
}
-#endif
+#endif // DEBUG_ENABLED