Commit graph

275 commits

Author SHA1 Message Date
ocean (they/them) 6783ff69c0 Improve and fix GDScript documentation generation & behavior
Removes documentation generation (docgen) from the GDScript compiler to
its own file. Adds support for GDScript enums and signal parameters and
quite a few other assorted fixes and improvements.
2023-04-21 10:17:30 -04:00
Ninni Pipping e5365da03c [GDScript] Fix incorrect compound assignment
Reverts in-place compound assignments

Added test to ensure correctness
2023-04-14 11:28:44 +02:00
Pedro J. Estébanez 2f4168daeb Fix edge cases of object lifetime when signals involved 2023-04-11 17:27:39 +02:00
Yuri Sizov a008a06fcb
Merge pull request #72056 from resistor/master
[GDScript] Perform update-and-assign operations in place when possible.
2023-03-20 19:16:30 +01:00
Dmitrii Maganov 55a2ad25bf GDScript: Fix checking if a call is awaited in compiler 2023-03-01 09:31:35 +02:00
Rémi Verschelde c0f1ed57c4
Merge pull request #73915 from vonagam/fix-conversions-from-native-member
GDScript: Fix conversions from native members accessed by identifier
2023-02-26 19:02:27 +01:00
Rémi Verschelde 1bd0b296e1
Merge pull request #73964 from vonagam/fix-coroutine-compiler-type
GDScript: Fix address type for coroutine results
2023-02-26 16:00:17 +01:00
Rémi Verschelde c118790eb9
Merge pull request #73899 from vnen/gdscript-init-defaults-beforehand
GDScript: Initialize all defaults beforehand in implicit constructor
2023-02-26 15:59:27 +01:00
Dmitrii Maganov 4efaf15605 GDScript: Fix address type for coroutine results 2023-02-26 08:30:46 +02:00
George Marques eba984a44f
Revert "GDScript: Fix groups and categories been seen as members"
This reverts commit 6f2a8434c6.

The commit introduces a bug where it creates spurious entries for member
information.
2023-02-25 13:40:31 -03:00
Dmitrii Maganov 281c8c75d3 GDScript: Fix conversions from native members accessed by identifier 2023-02-25 10:53:36 +02:00
George Marques 0e6aa6fc38
GDScript: Initialize all defaults beforehand in implicit constructor
Set all the default values for typed variables before actually trying to
initialize them, including `@onready` ones.

This ensures that if validated calls are being used there will be a
value of the correct type, even if the resolution is done out of order
or deferred because of `@onready`.
2023-02-24 22:01:06 -03:00
George Marques 6f2a8434c6
GDScript: Fix groups and categories been seen as members 2023-02-24 10:03:12 -03:00
George Marques d076c76551
GDScript: Fix setting native type with script inheritance
Sometimes the inheritance tree is compiled out of order and the base
don't have yet a native type set. This is now changed to not rely on the
base script but use the native type set in the datatype, which is
already resolved by the analyzer.
2023-02-21 14:09:10 -03:00
Dmitrii Maganov 8fe023ad93 GDScript: Rework type check 2023-02-17 19:57:18 +02:00
ocean (they/them) 94dfac8da7 Add return type for GDScript getters 2023-02-15 17:54:38 -05:00
Rémi Verschelde 98921d8fba
Revert "Remove script class checks when getting function signature"
This reverts commit 0fef203b1f.

This introduced some other issues, as discussed in #72144.
2023-02-07 16:28:52 +01:00
Adam Scott 0fef203b1f
Remove script class checks when getting function signature 2023-02-07 11:48:10 +01:00
George Marques a47d4d57ca
GDScript: Allow void functions to return calls to other void functions 2023-01-31 11:37:30 -03:00
Dmitrii Maganov 5909f9f075 GDScript: Fix issues with typed arrays 2023-01-31 11:54:41 +02:00
Dmitrii Maganov 011b3895db GDScript: Fix vararg method calls with exact arguments 2023-01-30 19:38:07 +02:00
Owen Anderson 22a0c200c6 [GDScript] Perform update-and-assign operations in place when possible.
This turns two bytecode operations into one by using the assignment
destination directly as the output of the binary operator. This manifests
in operations like `+=`.
2023-01-25 10:22:04 -06:00
George Marques ba9491f870
Merge pull request #70948 from vnen/gdscript-ptr-method-name-in-debug 2023-01-23 12:24:15 -03:00
George Marques 80e06b29e7
GDScript: Add names for disassembling function pointers
When instructions use function pointers, it's not possible to retrieve
their original names in the disassembly. This stores the names in
vectors (in debug builds) so they can be shown.
2023-01-23 11:04:31 -03:00
George Marques 9462ae4783
GDScript: Remove function of continue for match statement
The keyword is confusing and rarely is used in the intended way. It is
removed now in favor of a future feature (pattern guards) to avoid
breaking compatibility later.
2023-01-22 18:45:24 -03:00
Adam Scott 48e041458f Fix cyclic reference errors while reducing identifiers.
Co-authored-by: Dmitrii Maganov <vonagam@gmail.com>
2023-01-15 19:19:25 -05:00
George Marques 75515e4303
Merge pull request #70987 from vonagam/fix-parameter-conversion-assign 2023-01-12 11:34:13 -03:00
Rémi Verschelde 509da86205
Merge pull request #69590 from anvilfolk/enums
GDScript enum fixes & refactor
2023-01-09 23:10:37 +01:00
ocean (they/them) 366ec895b1 Assorted enum and native type fixes 2023-01-09 11:08:07 -05:00
George Marques a3816434a6
GDScript: Don't use the NIL address to hold return value of functions
This prevents that the NIL address is filled with another value, which
causes problems for some instructions that read from NIL.
2023-01-09 09:20:18 -03:00
Dmitrii Maganov a8c2f8a0e1 GDScript: Fix missing conversion for default argument values 2023-01-06 11:49:06 +02:00
Dmitrii Maganov 10e364bf43 GDScript: Fix array as default value for parameter 2023-01-06 06:25:55 +02:00
Dmitrii Maganov a1d06749f1 Unify typing of variables, constants and parameters in GDScript 2023-01-06 01:10:04 +02:00
Rémi Verschelde d95794ec8a
One Copyright Update to rule them all
As many open source projects have started doing it, we're removing the
current year from the copyright notice, so that we don't need to bump
it every year.

It seems like only the first year of publication is technically
relevant for copyright notices, and even that seems to be something
that many companies stopped listing altogether (in a version controlled
codebase, the commits are a much better source of date of publication
than a hardcoded copyright statement).

We also now list Godot Engine contributors first as we're collectively
the current maintainers of the project, and we clarify that the
"exclusive" copyright of the co-founders covers the timespan before
opensourcing (their further contributions are included as part of Godot
Engine contributors).

Also fixed "cf." Frenchism - it's meant as "refer to / see".
2023-01-05 13:25:55 +01:00
Rémi Verschelde 4e360ac612
Merge pull request #70702 from vnen/gdscript-error-on-assign-void
GDScript: Error when assigning return value of void function
2023-01-03 12:23:00 +01:00
Rémi Verschelde a797fa3b3d
Merge pull request #70503 from rune-scape/inner-class-docs
Inner classes get their docs back
2023-01-03 12:15:44 +01:00
George Marques 0c15844551
GDScript: Error when assigning return value of void function
This also makes built-in method calls empty the return value when the
method is void, to avoid keeping returning a garbage value in such case.
2022-12-30 12:08:58 -03:00
Dmitrii Maganov b6aa4840d8 Fix usage of Enum as constant 2022-12-28 23:04:40 +02:00
rune-scape 1b77993257 Inner classes get their docs back 2022-12-23 17:39:24 -05:00
Rémi Verschelde ae4c025da9
Merge pull request #69991 from rune-scape/cast-type
GDScript: Fix cast producing null
2022-12-23 09:22:21 +01:00
rune-scape e1c63fee86 GDScript: Fix built-in script and other find_class bugs 2022-12-15 14:56:23 -05:00
rune-scape 2dfc6d5b69 GDScript: Allow out of order member resolution 2022-12-14 21:44:05 -05:00
rune-scape 7d0d6aa16f GDScript: Fix cast producing null 2022-12-12 19:57:26 -05:00
ocean (they/them) c8293a73b4 Add GDScript member initializer implicit type conversion 2022-12-11 16:55:02 -05:00
Rémi Verschelde f6ea295bb1
Merge pull request #69467 from rune-scape/rune-subclass-script-path
GDScript: Fix subclass script path issues
2022-12-10 10:21:19 +01:00
Rémi Verschelde 907298d673
Merge pull request #68747 from rune-scape/rune-stringname-unification
GDScript: Unify StringName and String
2022-12-09 18:06:48 +01:00
rune-scape e79be6ce07 Unify String and StringName 2022-12-05 21:46:47 -05:00
Dmitrii Maganov 97280279ee Fix incomplete shadowing of member properties by parameters 2022-12-06 00:22:56 +02:00
rune-scape d531869a7c GDScript: Fix subclass script path issues 2022-12-01 20:43:27 -05:00
Yuri Rubinsky 8d2506e811 Reset unassigned local variables to null in the loops 2022-11-28 19:45:24 +03:00
Adam Scott 4e60689695 Fix cyclic reference base being loaded but not valid (which is ok) 2022-11-27 15:50:19 -05:00
Adam Scott 5704055d30 Fix cyclic references in GDScript 2.0 2022-11-18 16:41:31 -05:00
Rune 61df8f4484 GDScript Compiler: regression fix 2022-11-15 22:20:49 -06:00
Rune bce6f1792e GDScript compiler subclass bugfixes 2022-11-13 02:29:21 -08:00
Yuri Rubinsky f11b66b084 Fix named enums to use int64 type 2022-11-08 11:20:28 +03:00
bruvzg 0103af1ddd
Fix MSVC warnings, rename shadowed variables, fix uninitialized values, change warnings=all to use /W4. 2022-10-07 11:32:33 +03:00
Andy Maloney 127e2333f4 Remove redundant "if" condition in GDScriptCompiler::_parse_function()
Looking at the original PR, I believe this is the original intent, but it now means that previously dead code is now executed.
2022-09-24 12:30:43 -04:00
Fabio Alessandrelli ca7d572908 [Net] Modularize multiplayer, expose MultiplayerAPI to extensions.
- RPC configurations are now dictionaries.
- Script.get_rpc_methods renamed to Script.get_rpc_config.
- Node.rpc[_id] and Callable.rpc now return an Error.
- Refactor MultiplayerAPI to allow extension.
- New MultiplayerAPI.rpc method with Array argument (for scripts).
- Move the default MultiplayerAPI implementation to a module.
2022-07-26 09:31:12 +02:00
cdemirer 52781535a3 Check for parameters shadowing class members 2022-07-18 00:28:27 +03:00
Yuri Sizov f85bafaa11 Add grouping annotations for class properties in GDScript 2022-07-05 22:01:40 +03:00
cdemirer a0608bd891 Fix set chain bug with jump_if_shared 2022-06-28 18:45:27 +03:00
Rémi Verschelde c4a426d6ec
Merge pull request #62462 from vnen/gdscript-setter-chaining
GDScript: Fix setter being called in chains for shared types
2022-06-27 23:25:53 +02:00
George Marques 511a4b761c
GDScript: Fix setter being called in chains for shared types
When a type is shared (i.e. passed by reference) it doesn't need to be
called in a setter chain (e.g. `a.b.c = 0`) since it will be updated in
place.

This commit adds an instruction that jumps when the value is shared so
it can be used to skip those cases and avoid redundant calls of setters.
It also solves issues when assigning to sub-properties of read-only
properties.
2022-06-27 12:09:51 -03:00
George Marques cf015673d3
GDScript: Use implicit method for @onready variables
Initialize them with the implicit method so they're not related to the
overriding of the `_ready` method of the script but instead are always
set.
2022-06-24 14:49:21 -03:00
George Marques 81cac4907f
GDScript: Don't add implicit constructor to the list of functions
So it's not shown on docs or when listing the methods. This also avoids
being able to call it using the `call()` function.
2022-06-24 14:48:46 -03:00
bruvzg 860e24683f
Make enum/constant binds 64-bit. 2022-06-17 16:36:26 +03:00
George Marques 15740c37a3
Merge pull request #57151 from cdemirer/fix-match-array-dict-pattern-logic-error
Fix logic errors in match-statement Array & Dictionary patterns
2022-06-14 21:30:05 -03:00
George Marques eba3e0a9fc
GDScript: Support % in shorthand for get_node
The `%` is used in scene unique nodes. Now `%` can also be used instead
of `$` for the shorthand, besides being allowed generally anywhere in
the path as the prefix for a node name.
2022-05-27 13:46:18 -03:00
Yuri Rubinsky 5d95a5a024 Fix crash when extending inner class in GDScript 2022-05-18 16:53:24 +03:00
reduz 746dddc067 Replace most uses of Map by HashMap
* Map is unnecessary and inefficient in almost every case.
* Replaced by the new HashMap.
* Renamed Map to RBMap and Set to RBSet for cases that still make sense
  (order matters) but use is discouraged.

There were very few cases where replacing by HashMap was undesired because
keeping the key order was intended.
I tried to keep those (as RBMap) as much as possible, but might have missed
some. Review appreciated!
2022-05-16 10:37:48 +02:00
reduz 8b7c7f5a75 Add a new HashMap implementation
Adds a new, cleaned up, HashMap implementation.

* Uses Robin Hood Hashing (https://en.wikipedia.org/wiki/Hash_table#Robin_Hood_hashing).
* Keeps elements in a double linked list for simpler, ordered, iteration.
* Allows keeping iterators for later use in removal (Unlike Map<>, it does not do much
  for performance vs keeping the key, but helps replace old code).
* Uses a more modern C++ iterator API, deprecates the old one.
* Supports custom allocator (in case there is a wish to use a paged one).

This class aims to unify all the associative template usage and replace it by this one:
* Map<> (whereas key order does not matter, which is 99% of cases)
* HashMap<>
* OrderedHashMap<>
* OAHashMap<>
2022-05-12 11:21:29 +02:00
Hugo Locurcio 180e5d3028
Remove RES and REF typedefs in favor of spelled out Ref<>
These typedefs don't save much typing compared to the full `Ref<Resource>`
and `Ref<RefCounted>`, yet they sometimes introduce confusion among
new contributors.
2022-05-03 01:43:50 +02:00
George Marques 01d13ab2c1
GDScript: Allow using self in lambdas 2022-04-24 21:49:02 -03:00
George Marques cdbd6056ef
GDScript: Fix method call on singletons 2022-04-08 12:20:57 -03:00
George Marques 4710e2b278
GDScript: Add support for static method calls in native types 2022-04-06 14:14:38 -03:00
Rémi Verschelde 79bbe57244
Merge pull request #56830 from strank/parent-signals 2022-03-04 17:29:49 +01:00
Rémi Verschelde 4bbd7417c4
Merge pull request #58320 from mphe/fix_object_typed_arrays 2022-03-04 14:49:06 +01:00
cdemirer 3afe50c2fa Fix logic errors in match-statement Array & Dictionary Patterns 2022-03-02 19:05:18 +08:00
Marvin Ewald cea0630fef Fix typed arrays for Object based types
Fixes https://github.com/godotengine/godot/issues/53771.
2022-02-19 16:27:06 +01:00
SaracenOne ab2a8bd1d8 Fix using typed arrays based on script classes 2022-02-17 17:34:53 +00:00
strank dcf19f8914 Fix "Identifier not found" compiler error when accessing inherited signals or functions as callables. 2022-02-11 20:45:04 -05:00
George Marques ceafdf347e
GDScript: Treat enum values as int and enum types as dictionary
Since enums resolve to a dictionary at runtime, calling dictionary
methods on an enum type is a valid use case. This ensures this is true
by adding test cases. This also makes enum values be treated as ints
when used in operations.
2022-02-03 13:32:34 -03:00
George Marques ad6e2e82a9
GDScript: Consolidate behavior for assigning enum types
This makes sure that assigning values to enum-typed variables are
consistent. Same enum is always valid, different enum is always
invalid (without casting) and assigning `int` creates a warning
if there is no casting.

There are new test cases to ensure this behavior doesn't break in
the future.
2022-02-03 13:32:16 -03:00
strank 960a26f6c0 GDScript: Fix parsing default parameter values from function calls 2022-01-13 19:28:39 -05:00
SaracenOne 64d8b3aef2 Assign member type when parsing setters to prevent
'Compiler bug: unresolved assign' errors
2022-01-11 11:23:17 +00:00
Rémi Verschelde cc7f634066
Merge pull request #56260 from cdemirer/fix-type-mutation-upon-assignment-with-operation 2022-01-10 17:12:34 +01:00
Rémi Verschelde c8b4fe3b8d
Merge pull request #56287 from cdemirer/fix-member-property-only-getter-cant-be-set 2022-01-10 17:12:06 +01:00
Rémi Verschelde 1fd5954962
Merge pull request #56288 from cdemirer/fix-member-property-getter-dont-update-subscript-chain-root 2022-01-10 17:10:57 +01:00
Ger Hean 609964848d Fix leak when function returning self type
Leak is caused by cyclic reference
2022-01-10 02:14:48 +08:00
Rémi Verschelde fe52458154
Update copyright statements to 2022
Happy new year to the wonderful Godot community!
2022-01-03 21:27:34 +01:00
cdemirer bb9469aa65 Fix member properties with getters don't update as subscript chain root 2021-12-28 07:52:44 +08:00
cdemirer e8305e17ff Fix member properties with only getters can't be set 2021-12-28 07:51:18 +08:00
cdemirer 067b4c8c07 Fix type mutation upon compound assignment 2021-12-27 03:32:22 +08:00
Nathan Franke 49403cbfa0
Replace String comparisons with "", String() to is_empty()
Also:
- Adds two stress tests to test_string.h
- Changes to .empty() on std::strings
2021-12-09 04:48:38 -06:00
George Marques d36213bab8
GDScript: Make sure calls don't use return when not needed 2021-10-14 19:55:45 -03:00
ZuBsPaCe 551ceb590b GDScript: Report property type errors
Inline getters & setters are now FunctionNodes.
Their names are set in the parser, not in the compiler.
GDScript-Analyzer will now run through getter and setter.
Also report wrong type or signature errors regarding getset properties.
Added GDScript tests for getters and setters.
#53102
2021-10-08 22:06:15 +02:00
Brian Semrau c18a27a9cd GDScript fix wrong base class assignment 2021-10-04 20:38:08 -04:00
George Marques 84956fee4b
GDScript: Fix member assignment with operation
It was wrongly updating the assigned value with the result of the
operation.
2021-10-04 14:09:54 -03:00
Lightning_A c63b18507d Use range iterators for Map 2021-09-30 15:09:12 -06:00
George Marques 991f4d8527
GDScript: Fix assignment with operation for properties 2021-09-29 10:54:16 -03:00