diff options
Diffstat (limited to 'modules/gdscript/gdscript_editor.cpp')
-rw-r--r-- | modules/gdscript/gdscript_editor.cpp | 113 |
1 files changed, 59 insertions, 54 deletions
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 966a3db840..2ec3352e70 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -299,10 +299,10 @@ void GDScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p GDScriptFunction *f = _call_stack[l].function; - List<Pair<StringName, int> > locals; + List<Pair<StringName, int>> locals; f->debug_get_stack_member_state(*_call_stack[l].line, &locals); - for (List<Pair<StringName, int> >::Element *E = locals.front(); E; E = E->next()) { + for (List<Pair<StringName, int>>::Element *E = locals.front(); E; E = E->next()) { p_locals->push_back(E->get().first); p_values->push_back(_call_stack[l].stack[E->get().second]); @@ -336,9 +336,9 @@ void GDScriptLanguage::debug_get_stack_level_members(int p_level, List<String> * ScriptInstance *GDScriptLanguage::debug_get_stack_level_instance(int p_level) { if (_debug_parse_err_line >= 0) - return NULL; + return nullptr; - ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, NULL); + ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, nullptr); int l = _debug_call_stack_pos - p_level - 1; ScriptInstance *instance = _call_stack[l].instance; @@ -351,7 +351,7 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant> const Map<StringName, int> &name_idx = GDScriptLanguage::get_singleton()->get_global_map(); const Variant *globals = GDScriptLanguage::get_singleton()->get_global_array(); - List<Pair<String, Variant> > cinfo; + List<Pair<String, Variant>> cinfo; get_public_constants(&cinfo); for (const Map<StringName, int>::Element *E = name_idx.front(); E; E = E->next()) { @@ -360,7 +360,7 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant> continue; bool is_script_constant = false; - for (List<Pair<String, Variant> >::Element *CE = cinfo.front(); CE; CE = CE->next()) { + for (List<Pair<String, Variant>>::Element *CE = cinfo.front(); CE; CE = CE->next()) { if (CE->get().first == E->key()) { is_script_constant = true; break; @@ -430,11 +430,13 @@ void GDScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const mi.name = "assert"; mi.return_val.type = Variant::NIL; mi.arguments.push_back(PropertyInfo(Variant::BOOL, "condition")); + mi.arguments.push_back(PropertyInfo(Variant::STRING, "message")); + mi.default_arguments.push_back(String()); p_functions->push_back(mi); } } -void GDScriptLanguage::get_public_constants(List<Pair<String, Variant> > *p_constants) const { +void GDScriptLanguage::get_public_constants(List<Pair<String, Variant>> *p_constants) const { Pair<String, Variant> pi; pi.first = "PI"; @@ -499,10 +501,10 @@ struct GDScriptCompletionContext { uint32_t depth; GDScriptCompletionContext() : - _class(NULL), - function(NULL), - block(NULL), - base(NULL), + _class(nullptr), + function(nullptr), + block(nullptr), + base(nullptr), line(0), depth(0) {} }; @@ -514,7 +516,7 @@ struct GDScriptCompletionIdentifier { const GDScriptParser::Node *assigned_expression; GDScriptCompletionIdentifier() : - assigned_expression(NULL) {} + assigned_expression(nullptr) {} }; static void _get_directory_contents(EditorFileSystemDirectory *p_dir, Map<String, ScriptCodeCompletionOption> &r_list) { @@ -909,7 +911,7 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G Variant ret = mb->call(baseptr, (const Variant **)argptr.ptr(), argptr.size(), ce); if (ce.error == Callable::CallError::CALL_OK && ret.get_type() != Variant::NIL) { - if (ret.get_type() != Variant::OBJECT || ret.operator Object *() != NULL) { + if (ret.get_type() != Variant::OBJECT || ret.operator Object *() != nullptr) { r_type = _type_from_variant(ret); found = true; } @@ -963,7 +965,7 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G break; } - const GDScriptParser::DictionaryNode *dn = NULL; + const GDScriptParser::DictionaryNode *dn = nullptr; if (op->arguments[0]->type == GDScriptParser::Node::TYPE_DICTIONARY) { dn = static_cast<const GDScriptParser::DictionaryNode *>(op->arguments[0]); } else if (base.assigned_expression && base.assigned_expression->type == GDScriptParser::Node::TYPE_DICTIONARY) { @@ -1017,7 +1019,7 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G } // Look if it is a dictionary node - const GDScriptParser::DictionaryNode *dn = NULL; + const GDScriptParser::DictionaryNode *dn = nullptr; if (op->arguments[0]->type == GDScriptParser::Node::TYPE_DICTIONARY) { dn = static_cast<const GDScriptParser::DictionaryNode *>(op->arguments[0]); } else if (base.assigned_expression && base.assigned_expression->type == GDScriptParser::Node::TYPE_DICTIONARY) { @@ -1041,7 +1043,7 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G // Look if it is an array node if (!found && index.value.is_num()) { int idx = index.value; - const GDScriptParser::ArrayNode *an = NULL; + const GDScriptParser::ArrayNode *an = nullptr; if (op->arguments[0]->type == GDScriptParser::Node::TYPE_ARRAY) { an = static_cast<const GDScriptParser::ArrayNode *>(op->arguments[0]); } else if (base.assigned_expression && base.assigned_expression->type == GDScriptParser::Node::TYPE_ARRAY) { @@ -1061,7 +1063,7 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G found = _guess_identifier_type_from_base(c, base, id, r_type); } else if (!found && index.type.kind == GDScriptParser::DataType::BUILTIN) { Callable::CallError err; - Variant base_val = Variant::construct(base.type.builtin_type, NULL, 0, err); + Variant base_val = Variant::construct(base.type.builtin_type, nullptr, 0, err); bool valid = false; Variant res = base_val.get(index.value, &valid); if (valid) { @@ -1116,9 +1118,9 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G Callable::CallError ce; bool v1_use_value = p1.value.get_type() != Variant::NIL && p1.value.get_type() != Variant::OBJECT; - Variant v1 = (v1_use_value) ? p1.value : Variant::construct(p1.type.builtin_type, NULL, 0, ce); + Variant v1 = (v1_use_value) ? p1.value : Variant::construct(p1.type.builtin_type, nullptr, 0, ce); bool v2_use_value = p2.value.get_type() != Variant::NIL && p2.value.get_type() != Variant::OBJECT; - Variant v2 = (v2_use_value) ? p2.value : Variant::construct(p2.type.builtin_type, NULL, 0, ce); + Variant v2 = (v2_use_value) ? p2.value : Variant::construct(p2.type.builtin_type, nullptr, 0, ce); // avoid potential invalid ops if ((vop == Variant::OP_DIVIDE || vop == Variant::OP_MODULE) && v2.get_type() == Variant::INT) { v2 = 1; @@ -1173,7 +1175,7 @@ static bool _guess_identifier_type(GDScriptCompletionContext &p_context, const S // Look in blocks first const GDScriptParser::BlockNode *blk = p_context.block; int last_assign_line = -1; - const GDScriptParser::Node *last_assigned_expression = NULL; + const GDScriptParser::Node *last_assigned_expression = nullptr; GDScriptParser::DataType var_type; while (blk) { if (blk->variables.has(p_identifier)) { @@ -1227,7 +1229,7 @@ static bool _guess_identifier_type(GDScriptCompletionContext &p_context, const S r_type.type.is_meta_type = false; // Right-hand of `is` will be a meta type, but the left-hand value is not // Not an assignment, it shouldn't carry any value r_type.value = Variant(); - r_type.assigned_expression = NULL; + r_type.assigned_expression = nullptr; return true; } @@ -1271,8 +1273,8 @@ static bool _guess_identifier_type(GDScriptCompletionContext &p_context, const S return false; } GDScriptCompletionContext c = p_context; - c.function = NULL; - c.block = NULL; + c.function = nullptr; + c.block = nullptr; return _guess_expression_type(c, op->arguments[1], r_type); } } @@ -1534,7 +1536,7 @@ static bool _guess_identifier_type_from_base(GDScriptCompletionContext &p_contex } break; case GDScriptParser::DataType::BUILTIN: { Callable::CallError err; - Variant tmp = Variant::construct(base_type.builtin_type, NULL, 0, err); + Variant tmp = Variant::construct(base_type.builtin_type, nullptr, 0, err); if (err.error != Callable::CallError::CALL_OK) { return false; @@ -1612,7 +1614,7 @@ static bool _guess_method_return_type_from_base(GDScriptCompletionContext &p_con for (int i = 0; i < base_type.class_type->static_functions.size(); i++) { if (base_type.class_type->static_functions[i]->name == p_method) { int last_return_line = -1; - const GDScriptParser::Node *last_returned_value = NULL; + const GDScriptParser::Node *last_returned_value = nullptr; GDScriptCompletionContext c = p_context; c._class = base_type.class_type; c.function = base_type.class_type->static_functions[i]; @@ -1629,7 +1631,7 @@ static bool _guess_method_return_type_from_base(GDScriptCompletionContext &p_con for (int i = 0; i < base_type.class_type->functions.size(); i++) { if (base_type.class_type->functions[i]->name == p_method) { int last_return_line = -1; - const GDScriptParser::Node *last_returned_value = NULL; + const GDScriptParser::Node *last_returned_value = nullptr; GDScriptCompletionContext c = p_context; c._class = base_type.class_type; c.function = base_type.class_type->functions[i]; @@ -1704,7 +1706,7 @@ static bool _guess_method_return_type_from_base(GDScriptCompletionContext &p_con } break; case GDScriptParser::DataType::BUILTIN: { Callable::CallError err; - Variant tmp = Variant::construct(base_type.builtin_type, NULL, 0, err); + Variant tmp = Variant::construct(base_type.builtin_type, nullptr, 0, err); if (err.error != Callable::CallError::CALL_OK) { return false; } @@ -1911,8 +1913,8 @@ static void _find_identifiers_in_class(const GDScriptCompletionContext &p_contex base_type.value = p_context.base; GDScriptCompletionContext c = p_context; - c.block = NULL; - c.function = NULL; + c.block = nullptr; + c.function = nullptr; _find_identifiers_in_base(c, base_type, p_only_functions, r_result); } @@ -1932,8 +1934,8 @@ static void _find_identifiers_in_base(const GDScriptCompletionContext &p_context case GDScriptParser::DataType::CLASS: { GDScriptCompletionContext c = p_context; c._class = base_type.class_type; - c.block = NULL; - c.function = NULL; + c.block = nullptr; + c.function = nullptr; _find_identifiers_in_class(c, _static, p_only_functions, false, r_result); base_type = base_type.class_type->base_type; } break; @@ -1972,7 +1974,7 @@ static void _find_identifiers_in_base(const GDScriptCompletionContext &p_context } } if (!p_only_functions) { - for (const Map<StringName, Ref<GDScript> >::Element *E = script->get_subclasses().front(); E; E = E->next()) { + for (const Map<StringName, Ref<GDScript>>::Element *E = script->get_subclasses().front(); E; E = E->next()) { ScriptCodeCompletionOption option(E->key().operator String(), ScriptCodeCompletionOption::KIND_CLASS); r_result.insert(option.display, option); } @@ -2089,7 +2091,7 @@ static void _find_identifiers_in_base(const GDScriptCompletionContext &p_context } break; case GDScriptParser::DataType::BUILTIN: { Callable::CallError err; - Variant tmp = Variant::construct(base_type.builtin_type, NULL, 0, err); + Variant tmp = Variant::construct(base_type.builtin_type, nullptr, 0, err); if (err.error != Callable::CallError::CALL_OK) { return; } @@ -2153,8 +2155,8 @@ static void _find_identifiers(const GDScriptCompletionContext &p_context, bool p while (clss) { GDScriptCompletionContext c = p_context; c._class = clss; - c.block = NULL; - c.function = NULL; + c.block = nullptr; + c.function = nullptr; _find_identifiers_in_class(c, _static, p_only_functions, false, r_result); _static = true; clss = clss->owner; @@ -2188,7 +2190,7 @@ static void _find_identifiers(const GDScriptCompletionContext &p_context, bool p "const", "enum", "export", "onready", "static", "var", "break", "continue", "if", "elif", "else", "for", "pass", "return", "match", "while", "remote", "master", "puppet", "remotesync", "mastersync", "puppetsync", - 0 + nullptr }; const char **kw = _keywords; @@ -2234,6 +2236,8 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\""; +#define IS_METHOD_SIGNAL(m_method) (m_method == "connect" || m_method == "disconnect" || m_method == "is_connected" || m_method == "emit_signal") + while (base_type.has_type) { switch (base_type.kind) { case GDScriptParser::DataType::CLASS: { @@ -2250,7 +2254,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con } } - if ((p_method == "connect" || p_method == "emit_signal") && p_argidx == 0) { + if (IS_METHOD_SIGNAL(p_method) && p_argidx == 0) { for (int i = 0; i < base_type.class_type->_signals.size(); i++) { ScriptCodeCompletionOption option(base_type.class_type->_signals[i].name.operator String(), ScriptCodeCompletionOption::KIND_SIGNAL); option.insert_text = quote_style + option.display + quote_style; @@ -2263,7 +2267,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con case GDScriptParser::DataType::GDSCRIPT: { Ref<GDScript> gds = base_type.script_type; if (gds.is_valid()) { - if ((p_method == "connect" || p_method == "emit_signal") && p_argidx == 0) { + if (IS_METHOD_SIGNAL(p_method) && p_argidx == 0) { List<MethodInfo> signals; gds->get_script_signal_list(&signals); for (List<MethodInfo>::Element *E = signals.front(); E; E = E->next()) { @@ -2325,7 +2329,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con } } - if ((p_method == "connect" || p_method == "emit_signal") && p_argidx == 0) { + if (IS_METHOD_SIGNAL(p_method) && p_argidx == 0) { List<MethodInfo> signals; ClassDB::get_signal_list(class_name, &signals); for (List<MethodInfo>::Element *E = signals.front(); E; E = E->next()) { @@ -2334,6 +2338,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con r_result.insert(option.display, option); } } +#undef IS_METHOD_SIGNAL if (ClassDB::is_parent_class(class_name, "Node") && (p_method == "get_node" || p_method == "has_node") && p_argidx == 0) { // Get autoloads @@ -2373,7 +2378,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con case GDScriptParser::DataType::BUILTIN: { if (base.get_type() == Variant::NIL) { Callable::CallError err; - base = Variant::construct(base_type.builtin_type, NULL, 0, err); + base = Variant::construct(base_type.builtin_type, nullptr, 0, err); if (err.error != Callable::CallError::CALL_OK) { return; } @@ -2542,7 +2547,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path context.function = parser.get_completion_function(); context.line = parser.get_completion_line(); - if (!context._class || context._class->owner == NULL) { + if (!context._class || context._class->owner == nullptr) { context.base = p_owner; context.base_path = p_path.get_base_dir(); } @@ -2626,13 +2631,13 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path } GDScriptCompletionContext c = context; - c.function = NULL; - c.block = NULL; - c.base = base.value.get_type() == Variant::OBJECT ? base.value.operator Object *() : NULL; + c.function = nullptr; + c.block = nullptr; + c.base = base.value.get_type() == Variant::OBJECT ? base.value.operator Object *() : nullptr; if (base.type.kind == GDScriptParser::DataType::CLASS) { c._class = base.type.class_type; } else { - c._class = NULL; + c._class = nullptr; } _find_identifiers_in_base(c, base, is_function, options); @@ -2818,8 +2823,8 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path for (Map<StringName, GDScriptParser::ClassNode::Constant>::Element *E = clss->constant_expressions.front(); E; E = E->next()) { GDScriptCompletionIdentifier constant; GDScriptCompletionContext c = context; - c.function = NULL; - c.block = NULL; + c.function = nullptr; + c.block = nullptr; c.line = E->value().expression->line; if (_guess_expression_type(c, E->value().expression, constant)) { if (constant.type.has_type && constant.type.is_meta_type) { @@ -2887,9 +2892,9 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path } GDScriptCompletionContext c = context; - c._class = NULL; - c.function = NULL; - c.block = NULL; + c._class = nullptr; + c.function = nullptr; + c.block = nullptr; bool finding = true; index = index.right(index.find(".") + 1); while (index.find(".") != -1) { @@ -2917,8 +2922,8 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path GDScriptCompletionIdentifier constant; GDScriptCompletionContext c2 = context; c2._class = base_type.class_type; - c2.function = NULL; - c2.block = NULL; + c2.function = nullptr; + c2.block = nullptr; c2.line = E->value().expression->line; if (_guess_expression_type(c2, E->value().expression, constant)) { if (constant.type.has_type && constant.type.is_meta_type) { @@ -3220,7 +3225,7 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co v = v_ref; } else { Callable::CallError err; - v = Variant::construct(base_type.builtin_type, NULL, 0, err); + v = Variant::construct(base_type.builtin_type, nullptr, 0, err); if (err.error != Callable::CallError::CALL_OK) { break; } @@ -3440,7 +3445,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol // We cannot determine the exact nature of the identifier here // Otherwise these codes would work StringName enumName = ClassDB::get_integer_constant_enum("@GlobalScope", p_symbol, true); - if (enumName != NULL) { + if (enumName != nullptr) { r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_ENUM; r_result.class_name = "@GlobalScope"; r_result.class_member = enumName; |