Commit graph

1557 commits

Author SHA1 Message Date
Rémi Verschelde 4e06731346
Merge pull request #47958 from Xrayez/gdscript-rename-test-scripts
Rename GDScript test script filenames to use `snake_case`
2021-05-03 15:44:46 +02:00
Rémi Verschelde 5b16020846
Replace remaining uses of NULL with nullptr
Follow-up to #38736 (these uses were likely added after this PR was merged).
2021-04-29 11:53:27 +02:00
George Marques 9ed0f0384c
GDScript: Fix crash when base of an attribute is invalid
In attribute expressions (`a.b`) it's possible that the base has an
incorrect syntax and thus become a nullptr expression in the tree. This
commit add the check for this case to fail gracefully instead of
crashing.
2021-04-28 11:09:40 -03:00
George Marques c201b212c7
GDScript: Implement lambdas compilation and runtime 2021-04-28 11:09:38 -03:00
George Marques 3155368093
GDScript: Add lambdas to the type analyzer
- Lambdas are always callables (no specific signature match).
- Captures from the current context are evaluated.
2021-04-28 10:56:16 -03:00
George Marques c6e66a43b0
GDScript: Add lambda syntax parsing
Lambda syntax is the same as a the function syntax (using the same
`func` keyword) except that the name is optional and it can be embedded
anywhere an expression is expected. E.g.:

    func _ready():
        var my_lambda = func(x):
            print(x)
        my_lambda.call("hello")
2021-04-28 10:56:16 -03:00
Rémi Verschelde 8247667a3e
Core: Drop custom copymem/zeromem defines
We've been using standard C library functions `memcpy`/`memset` for these since
2016 with 67f65f6639.

There was still the possibility for third-party platform ports to override the
definitions with a custom header, but this doesn't seem useful anymore.
2021-04-27 16:26:27 +02:00
Hugo Locurcio 5d124c4a8f
Remove uses of auto for better readability and online code reviews
The current code style guidelines forbid the use of `auto`.

Some uses of `auto` are still present, such as in UWP code (which
can't be currently tested) and macros (where removing `auto` isn't
easy).
2021-04-26 14:59:28 +02:00
Rémi Verschelde d1dc28e46c
Merge pull request #48139 from vnen/gdscript-dict-keys
Fix mismatch between String and StringName in dictionary keys
2021-04-24 19:46:59 +02:00
Rémi Verschelde db90ab86b9
Merge pull request #47891 from Razoric480/lsp-update-filesystem
Make LSP update the filesystem for changed scripts
2021-04-24 13:17:31 +02:00
George Marques 1e4ff2ede6
GDScript: Make sure Lua-style dicts use StringName as keys 2021-04-23 16:00:23 -03:00
George Marques c7511de02e
GDScript: Fix resolution of dictionary keys
There was a mixup between String and StringName keys. Now they're
clearly separated. This also means you have to consider which type
you're using for the dictionary keys and how you are accessing them.
2021-04-23 15:42:33 -03:00
Rémi Verschelde a9ecf66342
Merge pull request #47956 from vnen/gdscript-double-stack
GDScript: Use special stack space for temporaries to reduce type changes
2021-04-20 17:39:09 +02:00
Andrii Doroshenko (Xrayez) 1e26bf23c2 Rename GDScript test script filenames to use snake_case 2021-04-16 22:16:19 +03:00
George Marques 9411bf05a4
GDScript: Adjust type of temporaries when needed 2021-04-16 12:04:08 -03:00
Rémi Verschelde 200d9a734c
Merge pull request #47701 from vnen/gdscript-test-runner 2021-04-16 10:34:39 +02:00
George Marques 40502a1689
GDScript: Pool temporary values by type on the stack
So the stack slots perform less type changes, which is useful for
future optimizations.
2021-04-14 14:35:51 -03:00
Francois Belair b16bb33a5b Make LSP update the filesystem of changed scripts
This updates global classes and exposes base member variables.
Fixes #39713
2021-04-14 13:12:39 -04:00
George Marques 8fc4a732de
Merge pull request #47330 from Blackiris/fix-corrupt-scene-when-export-has-setter
Fix corrupt scene when export var has setter
2021-04-14 10:00:57 -03:00
Julien Nguyen 79a16b8a44 Fix corrupt scene when export var has setter 2021-04-14 09:14:50 +02:00
Julien Nguyen 9936abb3d5 Fix type argument in is_builtin which was treated as an address 2021-04-11 20:34:48 +02:00
ray90514 1f9524bf57 Fix Constants at function scope are not defined as constants for autocompletion 2021-04-11 22:41:04 +08:00
Francois Belair 39f7408ccb Implement LSP didDeleteFiles & make parser aware of sub-nodes 2021-04-10 15:21:59 -04:00
George Marques cf4079cb5f
Reduce number of addressing modes in GDScript VM
There's now only 3 addressing modes: stack, constant, and member.

Self, class, and nil are now present respectively in the first 3 stack
slots. Global and class constants are moved to local constants when
compiling. Named globals is only present on editor to use on tool
singletons, so its use now emits a new instruction to copy the global to
the stack.

This allow us to further optimize the VM later by embedding the
addressing modes in the instructions themselves, which is better done
with less permutations.
2021-04-08 14:29:55 -03:00
George Marques 5f77f38573
Add runner for GDScript testing
This is meant for testing the GDScript implementation, not for testing
user scripts nor testing the engine using scripts.

Tests consists in a GDScript file and a .out file with the expected
output. The .out file format is: expected status (based on the enum
GDScriptTest::TestStatus) on the first line, followed by either an error
message or the resulting output. Warnings are added after the first
line, before the output (or compiler errors) if the parser pass without
any error.

The test script must have a function called `test()` which takes no
argument. Such function will be called by the test runner. The test
should not have any dependency unless it's part of the test too. Global
classes (using `class_name`) are registered before the runner starts, so
those should work if needed.

Use the command `godot --gdscript-generate-tests
godot-source/modules/gdscript/tests/scripts` to update the .out files
with the current output (make sure the output are the expected values
before committing).

The tests themselves are part of the doctest suite so those can be
executed with `godot --test`.

Co-authored-by: Andrii Doroshenko (Xrayez) <xrayez@gmail.com>
2021-04-08 09:34:59 -03:00
Rémi Verschelde 40dff7117a
Merge pull request #47648 from Blackiris/fix-gdscript-editor-hangs
Fix infinite loop when guessing argument type from parent class
2021-04-07 23:19:29 +02:00
Julien Nguyen 43c1c680f0 Fix stack overflow in setter 2021-04-06 19:00:08 +02:00
Julien Nguyen 20f18f1621 Fix infinite loop when guessing argument type from parent class 2021-04-05 16:39:41 +02:00
Rémi Verschelde 5b2c4ad91c
Merge pull request #47569 from vnen/gdscript-typed-return
GDScript: Properly validate return type
2021-04-05 15:16:43 +02:00
George Marques 35682d3079
GDScript: Properly validate return type
When the type cannot be validated at compile time, the runtime must do a
check to ensure type safety is kept, as the code might be assuming the
return type is correct in another place, leading to crashes if the
contract is broken.
2021-04-05 09:52:05 -03:00
Rémi Verschelde d83761ba80
Style: Apply clang-tidy's readability-braces-around-statements 2021-04-05 14:09:59 +02:00
Rémi Verschelde 9bbe51dc27
Style: Apply clang-tidy's modernize-use-nullptr 2021-04-05 14:05:07 +02:00
Julien Nguyen 3168c2a513 Fix GDScript variables addresses getting mixed 2021-04-04 19:03:15 +02:00
Rémi Verschelde 4b6e9f3157
Merge pull request #46991 from madmiraal/rename-invert-reverse
Rename Array.invert() to Array.reverse()
2021-04-01 13:32:22 +02:00
Rémi Verschelde 737f09895d
Merge pull request #47131 from vnen/gdscript-export-fix
Fix a few issues with @export in GDScript
2021-03-30 15:12:04 +02:00
Rémi Verschelde 7c14e987b4
Merge pull request #47492 from vnen/gdscript-typed-arrays
GDScript: Fix array type check on constants
2021-03-30 14:37:42 +02:00
George Marques 5d9585d83b
GDScript: Fix array type check on constants
They mistakenly pointing to the wrong union member (variable instead of
constant).
2021-03-30 09:09:13 -03:00
George Marques 2b9be53243
GDScript: Implement export of typed arrays 2021-03-30 08:29:38 -03:00
George Marques 160c260495
GDScript: Allow export of enum variables
Also fix the enum type in variables to be integer.
2021-03-30 08:29:38 -03:00
George Marques 3e4ecd9669
GDScript: Show error on invalid initializer expression 2021-03-30 08:29:38 -03:00
George Marques 577a17980d
Move GDSript annotation application after type-checking
This ensures that annotations that rely on the datatype (such as
@export) can validated it timely, allowing compound expressions instead
of only literal values.
2021-03-30 08:29:36 -03:00
Rémi Verschelde aba03110ba
Merge pull request #46830 from vnen/gdscript-typed-arrays
GDScript typed arrays
2021-03-29 16:47:38 +02:00
George Marques 85e316a5d5
Add typed arrays to GDScript
- Use `Array[type]` for type-hints. e.g.:
  `var array: Array[int] = [1, 2, 3]`
- Array literals are typed if their storage is typed (variable
  asssignment of as argument in function all). Otherwise they are
  untyped.
2021-03-29 10:45:48 -03:00
Rémi Verschelde eeba8d63f8
Merge pull request #44398 from RevoluPowered/unit-tests-for-export-templates
Add unit tests for export templates
2021-03-23 00:42:29 +01:00
Gordon MacPherson 6b4ff3b44b Add unit tests for export templates 2021-03-22 18:57:08 +00:00
Marcel Admiraal 755c70b871 Rename Array.invert() to Array.reverse()
Does the same internally for List and Vector<>, which includes all
PackedArray types.
2021-03-21 10:20:08 +00:00
Alex Hirsch d7ac5ba1c6 Fix missing quote in multiline GDScript string
fix #47117
2021-03-19 01:24:18 +01:00
Rémi Verschelde 6edb0a75ab
Merge pull request #46936 from DavidSichma/match_temp_header
Fixed match test expression for temporaries
2021-03-14 15:46:53 +01:00
David Sichma 762bb5843b
Fixed match test expression for temporaries
Fixed that a potentially popped temporary was used for the value in
match statements.
2021-03-12 15:04:45 +01:00
Anshul7sp1 91181c2086 Fixes small typos and grammar correction 2021-03-12 19:05:16 +05:30
Gilles Roudière ba1344408f Implement Navigation layers 2021-03-10 11:23:06 +01:00
Johannes 982a0ac348
Fix GDScript Tokenizer being very strict about the number of underscores
You can use multiple underscores in one number, just not two of them
together.
2021-03-06 01:57:37 +01:00
David Sichma 66a5002750
Fixed match for expression pattern
equality comparison now writes to right target address
2021-03-02 19:18:29 +01:00
George Marques 16e88f99e2
Merge pull request #42029 from ThakeeNathees/export-type-infer-bug-fix
GDScript export array/dictionary type infer bug fix
2021-03-02 12:14:57 -03:00
Rémi Verschelde d86369b590
Merge pull request #46559 from asmaloney/fix-code-completion
Script editor: Fix two special cases not being checked in code completion
2021-03-02 15:39:13 +01:00
Rémi Verschelde 75bfb016f2
Merge pull request #41897 from strank/not-in-conditional-done
Add a "not in" operator to GDScript.
2021-03-02 15:16:52 +01:00
Andy Maloney 4e89cb330b [script editor] Fix two special cases not being checked in code completion
When this code was changed for 4.0, a "break" statement inside a for loop in 3.x was changed to "return".

This means that the two special cases (autoloads and input actions) are never checked.

Removing the return lets these work properly in the editor.

(Also reorder conditionals to short-circuit and avoid expensive methods.)
2021-03-01 09:39:03 -05:00
Rémi Verschelde b7b70004bc
Merge pull request #46379 from ThakeeNathees/signal-idf-not-found-fix
GDScript: False positive "Identifier not found" error on signals fixed
2021-02-25 22:30:22 +01:00
Rémi Verschelde ee5ea64e83
Merge pull request #40276 from Taywee/master
remove invalid codeLensProvider value from lsp
2021-02-25 17:26:26 +01:00
Thakee Nathees 9869522e6a false positive "Identifier not found" error or signals fixed 2021-02-24 19:34:01 +05:30
Vignesh1-art a5d931033e
Fixed Invalid function bindings #46135
Fixed  GDScriptLanguageProtocol::notify_client - have 3 arguments, but only 2 are binded
2021-02-18 11:12:54 +05:30
reduz f8d03b98e7 Improve resource load cache
-Added a new method in Resource: reset_state , used for reloading the same resource from disk
-Added a new cache mode "replace" in ResourceLoader, which reuses existing loaded sub-resources but resets their data from disk (or replaces them if they chaged type)
-Because the correct sub-resource paths are always loaded now, this fixes bugs with subresource folding or subresource ordering when saving.
2021-02-11 15:44:28 -03:00
Rafał Mikrut f7209b459b Initialize class/struct variables with default values in modules/ 2021-02-08 10:57:18 +01:00
Rémi Verschelde 5525cd85c6
Merge pull request #45315 from RandomShaper/modernize_thread
Modernize Thread
2021-01-31 15:24:56 +01:00
Pedro J. Estébanez 99fe462452 Modernize Thread
- Based on C++11's `thread` and `thread_local`
- No more need to allocate-deallocate or check for null
- No pointer anymore, just a member variable
- Platform-specific implementations no longer needed (except for the few cases of non-portable functions)
- Simpler for `NO_THREADS`
- Thread ids are now the same across platforms (main is 1; others follow)
2021-01-29 12:02:13 +01:00
Aaron Franke e829b7aee4
Unify URI encoding/decoding and add to C#
http_escape and percent_encode have been unified into uri_encode, and http_unescape and percent_decode have been unified into uri_decode.
2021-01-28 07:45:01 -05:00
Lucas Van Mol 749d0c708c Fix highlight color for class attributes that are also keywords 2021-01-26 15:17:18 +01:00
Rémi Verschelde 51992250e6
Merge pull request #43176 from mateosss/crash-uninit-const
Fix crash by adding nullcheck for uninitialized constants
2021-01-11 14:00:54 +01:00
Rémi Verschelde 6d48943768
Merge pull request #43980 from gvekan/fix-missing-function-hints
Fix missing function hints
2021-01-11 13:54:22 +01:00
Rémi Verschelde c17413f159
Merge pull request #44104 from nekomatata/coroutine-await-fix
Fix error when calling coroutine with await in _ready
2021-01-11 13:54:04 +01:00
Rémi Verschelde 813bdb4941
Merge pull request #44005 from RandomShaper/gds_needless_check
Remove useless check in GDScript
2021-01-11 13:53:52 +01:00
Rémi Verschelde 3e9a40cdc0
Merge pull request #44604 from lyuma/gdscript_dictionary_crash
GDScript: Fix crash when iterating through empty dictionary.
2021-01-11 13:53:12 +01:00
Rémi Verschelde 8363c44265
Merge pull request #44719 from ThakeeNathees/assert-argument-bug-fixed
GDScript assert message parsing bug fixed
2021-01-11 13:51:44 +01:00
Rémi Verschelde a2021588ca
Merge pull request #44672 from ThakeeNathees/array-dict-const-fold-bug-fix
Array/Dictionary marked as not safe to const fold
2021-01-11 13:51:31 +01:00
Rémi Verschelde bcfb698fb4
Merge pull request #44818 from ThakeeNathees/const-crash-fix
GDScript crash at incomplete const bug fix
2021-01-11 13:51:18 +01:00
Rémi Verschelde aaf6725150
Merge pull request #44889 from ThakeeNathees/builtin-invalid-call-crash-fix
GDScript invalid method call on built-in crash fix
2021-01-11 13:51:07 +01:00
Rémi Verschelde 0dba21a4d1
Merge pull request #45076 from ThakeeNathees/gdscript-operator-precedence-bug-fix
GDScript operator `+` `-` precedence bug fix
2021-01-11 13:50:00 +01:00
Thakee Nathees 0889f14af9 GDScript operator + - precedence bug fix
Fix: #43265
2021-01-10 18:33:05 +05:30
Rémi Verschelde 215d18814e
doc: Sync classref with current source 2021-01-04 14:33:44 +01:00
Thakee Nathees 01c11ec29b GDScript builtin invalid function call crash fix
Fix: #44852
2021-01-03 18:44:01 +05:30
Rémi Verschelde b5334d14f7
Update copyright statements to 2021
Happy new year to the wonderful Godot community!

2020 has been a tough year for most of us personally, but a good year for
Godot development nonetheless with a huge amount of work done towards Godot
4.0 and great improvements backported to the long-lived 3.2 branch.

We've had close to 400 contributors to engine code this year, authoring near
7,000 commit! (And that's only for the `master` branch and for the engine code,
there's a lot more when counting docs, demos and other first-party repos.)

Here's to a great year 2021 for all Godot users 🎆
2021-01-01 20:19:21 +01:00
Thakee Nathees 18f30dda63 GDScript crash at incomplete const bug fix 2020-12-30 23:27:46 +05:30
Marcel Admiraal b743a2ef3c Rename Math::stepify to snapped 2020-12-28 13:01:30 +00:00
Marcel Admiraal 5b937d493f Rename empty() to is_empty() 2020-12-28 10:39:56 +00:00
Thakee Nathees ebade0e454 GDScript assert message parsing bug fixed
Fix: #43540
2020-12-27 13:13:50 +05:30
Thakee Nathees 16bb01adfb Array/Dictionary marked as not safe to const fold
Fix: #44459
2020-12-25 12:33:55 +05:30
Lyuma 0d4b750051 Fix crash when iterating through empty dictionary. 2020-12-21 20:15:29 -08:00
PouleyKetchoupp 2e4ee06b7a Fix error when calling coroutine with await in _ready
The code paths for calling async functions seemed to be missing in some
cases, causing a debug break and false positive error.
2020-12-17 09:01:39 -07:00
Rémi Verschelde 88b8c3ec00
Merge pull request #44424 from briansemrau/gdscript-fix-and
Fix gdscript `and` operator
2020-12-16 14:42:56 +01:00
Brian Semrau 61ac640aa0 Fix gdscript and operator 2020-12-16 07:41:10 -05:00
Jordan Schidlowsky 7d07e20bda fixes crash in disassemlber for opcode OPCODE_ASSIGN_TYPED_NATIVE 2020-12-15 21:44:52 -06:00
Rémi Verschelde 94b15bfb89
Merge pull request #44275 from vnen/variant-function-arg-pointers
Use pointer parameters in Variant function pointers
2020-12-15 20:52:03 +01:00
Rémi Verschelde abfc528439
Merge pull request #43890 from vnen/gdscript-builtin-functions-refactor
GDScript: Refactor builtin functions
2020-12-15 20:51:38 +01:00
skyace65 4fd20015f3 Pow method doc fix 2020-12-13 17:53:30 -05:00
George Marques e4e9231420
Use pointer parameters in Variant function pointers
Instead of references. This is needed because those function pointers
are used in GDNative which needs to work with plain C, which doesn't
support passing parameters by reference.
2020-12-10 18:18:47 -03:00
Rémi Verschelde cf62289d24
LSP: Fix iterator in enum API dump 2020-12-09 13:34:29 +01:00
bruvzg 644f739660
Static analyzer fixes:
Removes unused code in OS.
Fixes return types.
Fixes few typos.
2020-12-09 10:17:53 +02:00
Rémi Verschelde 90bdba576a
Merge pull request #43742 from qarmin/editor_modules_default_values
Initialize class/struct variables with default values in platform/ and editor/
2020-12-08 15:53:42 +01:00
Emmanuel Leblond a211812932
Constify ScriptLanguage.can_inherit_from_file 2020-12-08 13:06:15 +01:00
PouleyKetchoupp 87d73faa66 Fix base script not initialized properly in some cases
Storing script references to pointer only in result.script_type could
lead to losing the last reference, causing further conversions from
Script* to Ref<Script> to fail.

Now result.script_type_ref is always set first, and then cleared in the
specific case of the script being the owner, to avoid cyclic reference
issues.
2020-12-06 08:20:33 -07:00