Commit Graph

263 Commits

Author SHA1 Message Date
Aaron Riekenberg 417821fdd7
Only generate @kotlin.ExperimentalUnsigned annotation on create*Vector methods having an unsigned array type parameter. (#7881)
Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-04-28 17:10:01 +00:00
Max Burke a397dd7e8c
Optionally generate Python type annotations (#7858)
* optionally generate type prefixes and suffixes for python code

* fix codegen error when qualified name is empty

* WIP: Python typing

* more progress towards python typing

* Further iterate on Python generated code typing

* clang-format

* Regenerate code

* add documentation for Python type annotations option

* generate code with Python type annotations

* handle forward references

* clang-format
2023-04-28 09:38:29 -07:00
Jeroen Demeyer 6c8a8d054d
Go: make generated code more compliant to "go fmt" (#7907)
Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-04-26 05:19:07 +00:00
Jeroen Demeyer 63495b935a
Support file_identifier in Go (#7904)
Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-04-26 05:15:09 +00:00
Max Burke 56ecc1f548
Optionally generate type prefixes and suffixes for python code (#7857)
* optionally generate type prefixes and suffixes for python code

* fix codegen error when qualified name is empty

* generated code updated
2023-04-25 21:38:16 -07:00
tira-misu 876a64aae1
[CS] Verifier (#7850)
* Fix C/C++ Create<Type>Direct with sorted vectors

If a struct has a key the vector has to be sorted. To sort the vector
you can't use "const".

* Changes due to code review

* Improve code readability

* Add generate of JSON schema to string to lib

* option indent_step is supported

* Remove unused variables

* Fix break in test

* Fix style to be consistent with rest of the code

* [TS] Fix reserved words as arguments (#6955)

* [TS] Fix generation of reserved words in object api (#7106)

* [TS] Fix generation of object api

* [TS] Fix MakeCamel -> ConvertCase

* [C#] Fix collision of field name and type name

* [TS] Add test for struct of struct of struct

* Update generated files

* Add missing files

* [TS] Fix query of null/undefined fields in object api

* Add .Net verfier

* Add some fuzz tests for .Net

* Remove additional files

* Fix .net test

* Changes due to PR

* Fix generated files

---------

Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-04-06 00:29:14 +02:00
Paulo Pinheiro d3d7e2ef99
ToCamelCase() when kLowerCamel now converts first char to lower. (#7838)
ToCamelCase(input, true) converts first char to upper case, but
ToCamelCase(input, false) keeps the case of the first char. We are
changing its behavior to force a lower case.

Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-03-15 01:09:24 +00:00
Derek Bailey 01834de25e
FlatBuffers Version 23.3.3 (#7852) 2023-03-03 11:46:55 -08:00
Derek Bailey ee848a02e1
FlatBuffers Version 23.1.21 (#7796) 2023-01-21 12:46:57 -08:00
Michael Le 1703662285
Flatbuffers Version 23.1.20 (#7794)
* Flatbuffers Version 23.1.20

* Fix warnings

* Fix warnings
2023-01-21 12:03:17 -08:00
Anton Bobukh b50b6be60a
[Kotlin] Control the generation of reflection with --reflect-names (#7775)
* [Kotlin] Control the generation of reflection with --reflect-names.
Tested:
```
$ cmake -G "Unix Makefiles" && make && ./tests/flatc/main.py
...
KotlinTests.EnumValAttributes
 [PASSED]
KotlinTests.EnumValAttributes_ReflectNames
 [PASSED]
KotlinTests: 2 of 2 passsed
...

35 of 35 tests passed
```

* [Kotlin] Fix SampleBinary by converting Byte to UByte for ubyte fields.

* [Kotlin] Annotate all generated classes with kotlin.ExperimentalUnsignedTypes.
2023-01-10 10:03:39 -08:00
Florian Wagner e61b00359b
[Kotlin] Improve field nullability based on (required) (#7658)
* [Kotlin] Only generate nullable return types if the field is not required

* [Kotlin] Fix generated code formatting according to kotlin style guide

Co-authored-by: Derek Bailey <derekbailey@google.com>
Co-authored-by: Paulo Pinheiro <paulovictor.pinheiro@gmail.com>
2023-01-06 04:16:31 +00:00
Anton Bobukh 07d9485146
Expand wildcard imports in the generated Kotlin files. (#7757)
Tested:

```
$ cmake -G "Unix Makefiles" && make && ./flattests
...
[ 99%] Linking CXX executable flatsamplebinary
[100%] Built target flatsamplebinary
ALL TESTS PASSED
```

Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-01-05 14:34:44 -08:00
Derek Bailey af9ceabeef
FlatBuffers Version 23.1.4 (#7758) 2023-01-04 15:22:46 -08:00
RishabhDeep Singh 449d5649d6
Fixed test cases (#7732)
* Fix Cannot find symbol and test case

* Add generated tests

Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-12-22 20:51:39 +00:00
Michael Le 96d438df47
Perform nil check on string fields when packing (#7719)
Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-12-22 20:28:00 +00:00
Michael Le e1a2f688e0
[Go] Fix bug where `bytes` wasn't being imported when using --gen-onefile flag (#7706)
* Fix bug one file import bug

* Create reset import function and add braces
2022-12-12 23:06:48 -08:00
Derek Bailey acf39ff056
FlatBuffers Version 22.12.06 (#7702) 2022-12-06 22:54:49 -08:00
Saman 533f75d91b
Fix java import wild card (#7672)
* Fix java import wild card

* fix java include

* Fix some import problems

* clang-format

* Sort imports

Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-11-28 17:27:55 -08:00
Derek Bailey 8f625561d0
FlatBuffers Version 22.11.23 (#7662) 2022-11-23 11:32:19 -08:00
Derek Bailey 9d2c04d629 FlatBuffers Version 22.11.22 2022-11-22 14:40:01 -08:00
Michael Le 60975d6f7e
Add key lookup support for tables in Go (#7644)
* Add support for key lookup for tables in Go

* Run clang format

* Run go fmt on tests

* Remove TODO in tests

* Update LookupByKey API

* Update LookupByKey API

* Don't use resolvePointer in expectEq

* Use generated getters instead of reading values directly from buffer

* Fix typo

Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-11-22 14:08:19 -08:00
Gh0u1L5 41d6903294
[Go] Fix GenNativeUnionUnPack for imported union type. (#7579)
* Fix GenNativeUnionUnPack for imported union type.

* Update test results.

Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-11-13 11:52:02 -08:00
Alex-Ratcliffe f20b0a45b3
Add comparison operator to python objects under --gen-compare option (#7610)
* Add comparison operator to python code generator

* Missing semi-colon

* Regenerate test examples

Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-11-11 02:47:53 +00:00
James Kuszmaul 8aa8b9139e
Fix handling of +/-inf defaults in TS/rust/go/dart codegen (#7588)
+/-inf were not being handled, and so invalid typescript was being
generated when a float/double had an infinite default value. NaN was
being handled correctly.

Co-authored-by: Derek Bailey <derekbailey@google.com>
Co-authored-by: Casper <casperneo@uchicago.edu>
2022-11-08 10:59:46 -08:00
Derek Bailey 203241ed32
FlatBuffers Version 22.10.26 (#7607) 2022-10-26 16:02:38 -07:00
Joshua Smith 043a24f2e4
[Python] Fixed the issue with nested unions relying on InitFromBuf. (#7576)
* feat: Fixed the issue with nested unions relying on InitFromBuf.
Problem: Issue #7569
Nested Unions were broken with the introduction of parsing buffers with an initial encoding offset.

Fix:
Revert the InitFromBuf method to the previous version and introduction of InitFromPackedBuf that allows
users to read types from packed buffers applying the offset automatically.

Test:
Added in TestNestedUnionTables to test the encoding and decoding ability using a nested table with a
union field.

* fix: Uncommented generate code command
2022-10-26 14:56:52 -07:00
Derek Bailey a54ca1e759
FlatBuffers Version 22.10.25 (#7604) 2022-10-26 00:03:49 -07:00
Dan Lapid 872a497464
[Nim] Bfbs Nim Generator (#7534)
* Bfbs Nim Generator

* Remove commented out tests

* add missing line to idl.h

* Commit python reflection changes

* Commit python reflection changes and move tests

* Remove default string addition

* Move tests to python file

* Fix element size check when element is table

* remove whitespace changes

* add element_type docs and commit further to namer and remove kkeep

* Bfbs Nim Generator

* Remove commented out tests

* add missing line to idl.h

* Commit python reflection changes

* Commit python reflection changes and move tests

* Remove default string addition

* Move tests to python file

* Fix element size check when element is table

* remove whitespace changes

* add element_type docs and commit further to namer and remove kkeep

* remove unused variables

* added tests to ci

* added tests to ci

* fixes

* Added reflection type Field, Variable to namer

* Moved reflection namer impl to bfbsnamer

* Remove whitespace at end of line

* Added nim to generated code

* Revert whitespace removal

Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-10-21 14:30:04 -04:00
Dominic Battre e301702964
Make type conversions explicit. (#7595)
As Java does not support unsigned integer types, the value types
are "rounded up" (an uint32 is represented as a long) but persisted
correctly (an uint32 is persisted as 4 bytes).

This CL makes a cast operation explicit so that the compiler
does not throw warning messages.

Co-authored-by: Dominic Battre <battre@chromium.org>
Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-10-21 09:09:28 -07:00
Dominic Battre f7b734438d
Fix LongEnum definitions (#7596)
The MyGame/Example/LongEnum.java class did not compile because
Java expects an "L" suffix for literals of type long.

This CL fixes the code generation to include such a suffix.

Co-authored-by: Dominic Battre <battre@chromium.org>
2022-10-20 18:15:00 -07:00
Derek Bailey c92e78a9f8
FlatBuffers Version 22.9.29 (#7557) 2022-09-29 22:12:07 -07:00
Derek Bailey 76ddae006f
FlatBuffers Version 22.9.24 (#7547) 2022-09-27 11:55:25 -07:00
Joshua Smith 413115858c
[Python] Python fixed size array (#7529)
* feat: Added support for fixed sized arrays to python

Problem:
We encountered that using fixed arrays from C++ to python that python would
not read those arrays correctly due to no size information being encoded in the byte
array itself.

Fix:
Encode the sizes within the generated python file during code generation.
Specfically we add GetArrayAsNumpy to the python version of table, which takes as input
the length of the vector. When generating the python message files we include this length
from the VectorType().fixed_length.

* fix: added digit support for camel case to snake case conversion

Problem:
When including a number in the message name we would encounter cases where SnakeCase would
not add the appropirate breaks. e.g. Int32Stamped -> int_32stamped rather than int_32_stamped.

Fix:
To fix this we can add the condition that we check if the current character is not lower and
not a digit, that we check if the previous character was a lower or digit. If it was a lower
or digit then we add the break.

* fix: Array support for structures

Problem:
The python generated code for handling non-struct and struct vectors
and arrays was inconsistent. The calls to populate the obj api was
creating incorrect code.

Solution:
To fix this the VectorOfStruct and VectorOfNonStruct was rewritten
to handle array cases and bring the two methods in line which each
other.

Testing:
PythonTesting.sh now correctly runs and generates the code for
array_test.fbs.
Minor modifications were done on the test to use the new index
accessor for struct arrays and the script correctly sources the
location of the python code.

* chore: clang format changes

* Added code generated by scripts/generate_code. Modified GetArrayOfNonStruct slightly
to allow for function overloading allowing the user to get a single element of an array
or the whole array.

* Added new_line parameter to OffsetPrefix to allow optional new lines to be added.
This allows us to use the GenIndents method that automatically adds new lines instead.

* Reupload of generated code from the scripts/generate_code.py

* Removed new line in GetVectorAsNumpy.

* Updated Array lengths to use Length methods where possible. Added fallthrough for GenTypePointer. Added digit check to CamelToSnake method. Added and modified tests for ToSnakeCase and CamelToSnake.

* Added range check on the getter methods for vector and array types. Renamed == as is for python
2022-09-22 11:08:09 -07:00
Derek Bailey c5a609dc20
[C#] Prepares for official Nuget release (#7496)
* Define nuget package

* C# Switch to Google.FlatBuffers namespace

* Add Source Link for nuget package

* Add Strong Name signing of Google.FlatBuffers
2022-09-01 10:17:34 -07:00
Derek Bailey 06c5c7ed0b
FlatBuffers Version 2.0.8 (#7492) 2022-08-29 20:43:36 -07:00
Derek Bailey eeb8fd60d5
Include builder.addOffset for vector of structs (#7470) 2022-08-23 23:17:35 -07:00
Derek Bailey 8367664f15
Flatbuffers Version 2.0.7 (#7462) 2022-08-22 21:42:15 -07:00
Derek Bailey 214125e417
[C#] Rework how sorted vectors are looked up (#7441) 2022-08-15 09:33:07 -07:00
Andrei Burdulescu c793621567
[golang] Add support for text parsing with json struct tags (#7353)
* [golang] Add support for text parsing with json struct tags

Add struct tags to Go native structs generated when object API is used.

This allows to use the same JSON file as for C++ text
parsing(i.e. snake_case vs CamelCase) and thus enabling text parsing
for Go(when using object API).

* [golang] Add test for text parsing

Added small test to check and demonstrate text parsing in Go.
Also, ran clang-format on cpp file changes.
2022-08-08 11:30:06 -07:00
Paulo Pinheiro 7b5fd2bd05
[Kotlin] Fix key lookup returning null clashing with default value (#7237)
* [Java] Fix key lookup returning null clashing with default value

A field with key attribute must always be written on the message so it
can be looked up by key. There is a edge case where inserting a key
field with same value as default would prevent it to be written on
the message and later cannot be found when searched by key.

* [Kotlin] Fix key lookup returning null clashing with default value

A field with key attribute must always be written on the message so it
can be looked up by key. There is a edge case where inserting a key
field with same value as default would prevent it to be written on
the message and later cannot be found when searched by key.

Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-04-11 17:17:19 -07:00
Paulo Pinheiro 7181d77700
[Java] Fix key lookup returning null clashing with default value (#7236)
A field with key attribute must always be written on the message so it
can be looked up by key. There is a edge case where inserting a key
field with same value as default would prevent it to be written on
the message and later cannot be found when searched by key.
2022-04-11 17:16:41 -07:00
Jamie-Jameson c9651b7420
Add overloads for C# ByteBuffer/FlatBufferBuilder to allow adding vector blocks from ArraySegments or IntPtr (#7193)
* Add overloads to Add/Put for ArraySegment and IntPtr

In order to allow using code to reduce memory allocations, add overloads to ByteBuffer's and FlatBuffersBuilder's Put/Add methods that take ArraySegment<T> or IntPtr respectively.
Also, adaptions to the c# code generator in flatc to emit corresponding CreateVectorBlock() overloads

* Add missing files generated with generate_code.py

The previous commit changed the C# code generate, but didn't contain the updated generated test files.

* Incorporate review findings

(1) Adhere to 80 characters limit.
(2) In FlatBufferBuilder.Add(IntPtr,int), move zero length check topmost and add sanity check against negative input
2022-04-01 13:35:07 -07:00
Casper fac0d7be02
Apply Namer to Java. (#7194)
* Started applying Namer to Java.

- Java didn't previously have keyword escaping
- Added prefixes and suffixes to the Namer methods
- TODO: migrate previous namer applications to using pre/suffixes
- Java methods / functions are interesting, it's mostly camel case
  except when it involves a struct/enum name. That section is Keep case
- I changed the casing for some internal arguments/variables. This
  violates the "don't change genfiles" rule that I've been using but it
  shouldn't break user code.
- LegacyJavaMethod2 is interesting. Basically, Java has a "mixed" case
  convention where it's camel case, except for the type/variant name
  itself, which is keep case. So a type foo_bar would become getfoo_bar
  instead of getFooBar.

* small fix

* Namer for Namespaces

* removed unused parameter, add const everywhere

* Remove unused argument

* More unused args

* Use mutable reference out parameters

* Made more strings const and inlined const empty strings

* remove do not submit

Co-authored-by: Casper Neo <cneo@google.com>
2022-03-30 18:13:16 -04:00
tira-misu 2ad408697f
[TS] Fix generation of struct members in object api (#7148)
* Fix C/C++ Create<Type>Direct with sorted vectors

If a struct has a key the vector has to be sorted. To sort the vector
you can't use "const".

* Changes due to code review

* Improve code readability

* Add generate of JSON schema to string to lib

* option indent_step is supported

* Remove unused variables

* Fix break in test

* Fix style to be consistent with rest of the code

* [TS] Fix reserved words as arguments (#6955)

* [TS] Fix generation of reserved words in object api (#7106)

* [TS] Fix generation of object api

* [TS] Fix MakeCamel -> ConvertCase

* [TS] Add test for struct of struct of struct

* Update generated files

* Add missing files

* [TS] Fix query of null/undefined fields in object api
2022-03-23 21:40:11 -07:00
James Kuszmaul 9ed1323044
Fix 64-bit numeric enum values in typescript (#7135)
* Fix 64-bit default numeric enum values in typescript

If you had a default value that wasn't a valid enum value (e.g., a zero
if you used a bit_flag setting, like you get with AdvancedFeatures
in reflection.fbs), we weren't using BigInt.

* Run generate_code.py

* [DART] Handle deprecated fields & invalid enum defaults

* Update .NET test
2022-03-04 21:57:48 -08:00
Casper 615616cb55
Change Rust generated file defaults (#7101)
* Change Rust generated file defaults

After #6731, flatc changed its default behavior
for generating rust code to fix some importing issues.
This was a breaking change which invlidated the patch release,
`flatc 2.0.5` (#7081). This PR reverses the default so we can
release a patch update. However, does break Rust users who work at
HEAD.

* Bump flatc patch version (2.0.6)

Co-authored-by: Casper Neo <cneo@google.com>
2022-02-15 11:48:42 -05:00
Aaron Riekenberg 15df50eb7f
Remove @ExperimentalUnsignedTypes annotation from kotlin code generator. (#7092) 2022-02-13 20:29:36 -08:00
Derek Bailey 39c8a19ce2
fixed comparator for native_inline (#7076)
* fixed comparator for native_inline

* added native_inline data

* updated more tests for the new field

* more fixes
2022-02-02 23:44:43 -08:00
lu-wang-g 5fc87f4c4b
Enable --gen-onefile in Python (#6953)
* Enable --gen-onefile in Python

Made it possible to generate all python code in one file. Modified
py_test.py so that it can switch between the multi-file code and
the one-file code.

Updated PythonTest.sh and py_test.py so that the multi-file code
and the one-file code can be tested based on the same test code.

* Sync with google/flatbuffers

* Add --gen-onefile to generate_code.py
2021-12-09 15:47:09 -08:00