1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

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.
This commit is contained in:
George Marques
2018-05-29 23:16:54 -03:00
parent f7793fc5c9
commit 743053734f
9 changed files with 2984 additions and 286 deletions

View File

@@ -42,6 +42,22 @@
class GDScriptInstance;
class GDScript;
struct GDScriptDataType {
bool has_type;
enum {
BUILTIN,
NATIVE,
SCRIPT,
GDSCRIPT
} kind;
Variant::Type builtin_type;
StringName native_type;
Ref<Script> script_type;
GDScriptDataType() :
has_type(false) {}
};
class GDScriptFunction {
public:
enum Opcode {
@@ -139,6 +155,8 @@ private:
#endif
Vector<int> default_arguments;
Vector<int> code;
Vector<GDScriptDataType> argument_types;
GDScriptDataType return_type;
#ifdef TOOLS_ENABLED
Vector<StringName> arg_names;
@@ -199,6 +217,8 @@ public:
int get_max_stack_size() const;
int get_default_argument_count() const;
int get_default_argument_addr(int p_idx) const;
GDScriptDataType get_return_type() const;
GDScriptDataType get_argument_type(int p_idx) const;
GDScript *get_script() const { return _script; }
StringName get_source() const { return source; }