diff options
author | George Marques <george@gmarqu.es> | 2018-05-29 23:16:54 -0300 |
---|---|---|
committer | George Marques <george@gmarqu.es> | 2018-07-20 21:55:16 -0300 |
commit | 743053734f187c220250d88e4e475b7a87767cbc (patch) | |
tree | 414a571036bf8742cb0d04a68063a84c73eded5b /modules/gdscript/gdscript_editor.cpp | |
parent | f7793fc5c9b43b35c5ef1c53e02a8c251a8ba4a4 (diff) | |
download | redot-engine-743053734f187c220250d88e4e475b7a87767cbc.tar.gz |
Add static type checks in the parser
- Resolve types for all identifiers.
- Error when identifier is not found.
- Match return type and error when not returning a value when it should.
- Check unreachable code (code after sure return).
- Match argument count and types for function calls.
- Determine if return type of function call matches the assignment.
- Do static type check with match statement when possible.
- Use type hints to determine export type.
- Check compatibility between type hint and explicit export type.
Diffstat (limited to 'modules/gdscript/gdscript_editor.cpp')
-rw-r--r-- | modules/gdscript/gdscript_editor.cpp | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index c8d2d2e3e8..8389f57761 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -1236,15 +1236,11 @@ static bool _guess_identifier_type(GDScriptCompletionContext &context, int p_lin } //guess type in constant + if (context._class->constant_expressions.has(p_identifier)) { - for (int i = 0; i < context._class->constant_expressions.size(); i++) { - - if (context._class->constant_expressions[i].identifier == p_identifier) { - - ERR_FAIL_COND_V(context._class->constant_expressions[i].expression->type != GDScriptParser::Node::TYPE_CONSTANT, false); - r_type = _get_type_from_variant(static_cast<const GDScriptParser::ConstantNode *>(context._class->constant_expressions[i].expression)->value); - return true; - } + ERR_FAIL_COND_V(context._class->constant_expressions[p_identifier].expression->type != GDScriptParser::Node::TYPE_CONSTANT, false); + r_type = _get_type_from_variant(static_cast<const GDScriptParser::ConstantNode *>(context._class->constant_expressions[p_identifier].expression)->value); + return true; } if (!(context.function && context.function->_static)) { @@ -1372,8 +1368,8 @@ static void _find_identifiers_in_class(GDScriptCompletionContext &context, bool } if (!p_only_functions) { - for (int i = 0; i < context._class->constant_expressions.size(); i++) { - result.insert(context._class->constant_expressions[i].identifier); + for (Map<StringName, GDScriptParser::ClassNode::Constant>::Element *E = context._class->constant_expressions.front(); E; E = E->next()) { + result.insert(E->key()); } for (int i = 0; i < context._class->subclasses.size(); i++) { @@ -2320,9 +2316,8 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base options.insert(String(cl->variables[i].identifier)); } - for (int i = 0; i < cl->constant_expressions.size(); i++) { - - options.insert(String(cl->constant_expressions[i].identifier)); + for (Map<StringName, GDScriptParser::ClassNode::Constant>::Element *E = cl->constant_expressions.front(); E; E = E->next()) { + options.insert(String(E->key())); } } @@ -2816,13 +2811,10 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol //guess in class constants - for (int i = 0; i < context._class->constant_expressions.size(); i++) { - - if (context._class->constant_expressions[i].identifier == p_symbol) { - r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION; - r_result.location = context._class->constant_expressions[i].expression->line; - return OK; - } + if (context._class->constant_expressions.has(p_symbol)) { + r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION; + r_result.location = context._class->constant_expressions[p_symbol].expression->line; + return OK; } //guess in class variables |