Commit Graph

1038 Commits

Author SHA1 Message Date
Derek Bailey 40866a8927
fixed padding in struct for annotated binary (#7199) 2022-03-30 16:43:22 -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 6c5603fd98
[C#] Fix collision of field name and type name (#7149)
* 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 example for type field name collision
2022-03-30 12:51:58 -07:00
Derek Bailey 2d21853a7e monster fuzzer fix for json default scalars 2022-03-30 12:29:41 -07:00
Derek Bailey 7fd8576233
structured comments (#7192) 2022-03-29 10:01:32 -07:00
Casper a4cb1599d8
Namerdart (#7187)
* Apply Namer to Dart.

- Also refactor idl_gen_dart a bit
  - to use more const and references
  - out parameters should be the last argument

* Add keyword test

* minor fixes

* fix merge

* extra 's'

* move dart keyord into dart dir

* Address comments

* Use $ for escaping keywords
* Outparameters for namespace_map

* Escape dollar in toString

* Escape dollar in toString2

* Use UpperCamelCase for types and variants

* try to fix ToString

* namer Type fixes

* Remove path prefixing in imports

* gen code

Co-authored-by: Casper Neo <cneo@google.com>
2022-03-28 18:07:09 -04:00
Derek Bailey ae4ce72651
fuzzed binary annotator (#7188) 2022-03-25 22:58:15 -07:00
Derek Bailey e2be0c0b06
Handle root offset and root table vtable invalidation (#7177)
* Handle invalid root offset

* Handle vtable offset invalidation

* Added script generator. Add more cases through vtable ref table size

* review responses

* vtable offset validation

* Moved padding insertion to the end. Tests invalid field lenghts

* table offsets validated. Added type after field

* validate string length

* add todo

* invalid vector length

* invalid structs

* general cleanup

* reworded invalid offsets

* example for vector of structs

* invalid vector of tables

* invalid vector of strings

* invalid vector of scalars

* vector of unions

* validate union type value

* invalid vector union type values
2022-03-23 21:51:32 -07: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
Will Hughes 5a13f622cf
Correctly parse lists of enums in Dart generated code (#7157)
* Correctly parse lists of enums in Dart generated code

* Add a test for #6869

* Commit generated code

* Fixed missing newline-at-eof
2022-03-22 21:56:14 -07:00
James Kuszmaul eeb49c2757
Move flatbuffer_ts_library to typescript.bzl (#7183)
This makes it so that users of flatbuffer_cc_library don't need to have
rules_nodejs available in their WORKSPACE, addressing #7179.
2022-03-22 21:41:39 -07:00
Derek Bailey d3aeee32bb
Annotated Flatbuffer Binary (#7174)
* Annotated Flatbuffer Binary

* Various fixes

* Handles old schema

* handle multiple missing fields

* minor edits

* bazel fix, spelling fix, ascii fix
2022-03-18 14:08:05 -07:00
James Kuszmaul e5f331db99
[TS] Add single-file ts codegen & bazel rule for typescript (#7161)
The headline here is adding a flatbuffer_ts_library rule for generating
typescript code in bazel. This entails some non-trivial other changes,
but ideally none are user-visible.

In particular:
* Added a --ts-flat-file flag that generates a single *_generated.ts
  file instead of separate files for each typescript type. This makes
  bazel much happier.
* Import the bazel rules_nodejs stuff needed to support building
  typescript in bazel
* Move flatbuffers.ts to index.ts because I wasn't sure how to make
  bazel comprehend the "main" attribute of the package.json. Happy
  to take another stab at figuring that out if really needed.
* Fix another couple keyword escaping spots in typescript...
2022-03-10 10:08:13 -08:00
Wouter van Oortmerssen d648396515 [Lobster] file_identifier support 2022-03-08 15:39:12 -08:00
Wouter van Oortmerssen 777e78d8dd [Lobster] support unsigned integer reads
(depends on the latest Lobster version)
2022-03-08 15:13:34 -08:00
Casper 65a10b6e32
Implement a config based name manager and use it in Rust codegen (#7144)
* Refactor out a  class from Rust Codegen

* Convert GenerateRustModuleRootFile

* git-clang-format

* unused variable

* parenthesis

* update BUILD file

* buildifier

* Delete bfbs_gen_rust.h

* Delete bfbs_gen_rust.cpp

* Addressed some comments

* Namer::EnumVariant

* Remove do not submit; Add Namespace vector overload

* Unshadow variable

* removed redundant variables

* Warn if converting from kKeep case.

Co-authored-by: Casper Neo <cneo@google.com>
2022-03-05 20:43:57 -05:00
James Kuszmaul 8db2fef3f7
[TS] Escape keywords in typescript object names (#7137)
* Add Object to the list of reserved keywords.
* Properly escape keywords in type names.
* Properly escape keywords in enum names.
* Properly escape keywords in enum field names.
2022-03-05 09:39:59 -08: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
Derek Bailey 318594e4b4
prevent name clash (#7133) 2022-02-24 22:01:25 -08:00
Casper 3d903302c3
[Rust] Add length checks to arrays and vectors. (#7130)
* [Rust] Add length checks to arrays and vectors.

The previous behavior allowed for out of bounds access in
the public API (#7011).

* bump semver and test warning

Co-authored-by: Casper Neo <cneo@google.com>
2022-02-24 13:49:59 -05:00
Derek Bailey c9571d9897
Replaced ToDasherCase with ConvertCase (#7131) 2022-02-23 22:31:40 -06:00
Derek Bailey 3694b830a2
Use ConvertCase instead of Make{Upper,Lower,Snake} implementations (#7127)
* Unified name case conversion to single method

* Convert bfbs_gen to use ConvertCase

* convert rust to use ConvertCase

* Convert idl_parser to use ConvertCase

* Convert MakeScreamingCamel to ConvertCase

* Replaced MakeCamel with ConvertCase

* minor fixes
2022-02-23 18:08:11 -06:00
Derek Bailey 8a9303d464
update proto tests with alaised enum (#7121) 2022-02-22 01:03:46 -06:00
James Kuszmaul 9c52ec3744
Add deps attribute to flatbuffer_cc_library (#7107)
I'm not seeing the reason why we didn't attempt to support transitive
dependencies for flatbuffer_cc_library, and the current setup makes
having to propagate new dependencies to all of their recursive
dependents obnoxious.
2022-02-21 22:33:47 -06:00
Christopher Crawford 06f4af11b6
Go optional scalars (#7104)
* [go] always write required types

* support optional scalars in go

* generate optional_scalars and monster_test

* restore original behavior for non-optional scalars

* add tests
2022-02-16 15:02:54 -05: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
Wouter van Oortmerssen 3413c33004 Fixed FlexBuffers verifier fuzzer timing out
Change-Id: I3a408da08676e522069adf83730d6bcc2b5493b3
2022-02-14 12:01:52 -08:00
Aaron Riekenberg 15df50eb7f
Remove @ExperimentalUnsignedTypes annotation from kotlin code generator. (#7092) 2022-02-13 20:29:36 -08:00
Derek Bailey faadbc10ea
Add CreateVector overload to accept array like (#7095) 2022-02-09 22:16:46 -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
nicked a2b238960f
Fixed default value of bool in struct for Swift (#7072) 2022-02-02 23:39:19 +03:00
Derek Bailey bc901436db
clang format on codebase (#7058) 2022-02-01 11:23:18 -08:00
Derek Bailey 240be9b5ae
attempt to remove appveyor (#7056) 2022-01-31 21:52:15 -08:00
mustiikhalil 4f3b24db09
Fixes a bug where bools arent being nil when marked optional (#7051) 2022-01-31 18:12:57 +03:00
Max Burke 1d294a31b8
Implement Serialize on generated rust types (#7022)
* fix for rust build

* Rust: Implement Serialize on generated types

For debugging convenience it is really handy to be able to dump out
types as another format (ie: json). For example, if we are logging a
type to a structured logging system, or even printing it out in a
structured way to the console.

Right now we handle this by shelling out to `flatc` which is not ideal;
by implementing Serialize on the generated types we can use any of the
Serializer-implementing packages for our structured debug output.

* clang-format

* Make the flatbuffers Rust crate only have an optional dependency on the `serde` packages.

* fix warning

* fix rust test build

* Oh yeah this needs to be initialized

* fix toml syntax

* code review feedback

* rebuild test data
2022-01-30 19:29:18 -05:00
Jean-François Roy 43203984f7
[C++] Support C++ object copies and moves (#5988)
Augment the C++ generator to emit a C++ copy constructor and a by-value
copy assignment operator. This is enabled by default when the C++
standard is C++11 or later. These additional functions are only emitted
for objects that need it, typically tables containing other tables.

These new functions are declared in the object table type and are
defined as inline functions after table declarations.

When these new functions are declared, a user-defined
explicitly-defaulted default constructor and move constructor are also
emitted.

The copy assignment operator uses the copy-and-swap idiom to provide
strong exception safety, at the expense of keeping 2 full table copies
in memory temporarily.

fixes #5783
2022-01-29 14:24:24 -08:00
Justin T Conroy 19920db39f
Include a SizePrefixed..HasIdentifier for c++. (#6871)
* Include a SizePrefixed..HasIdentifier for c++.

* Add updated generated code.
2022-01-28 20:52:32 -08:00
Derek Bailey 028f0fde62
'flattest': Add --test_path option (#7041) 2022-01-27 14:21:01 -08:00
Jon Simantov a2d38fbb98
Add --warnings-as-errors to flatc compiler. (#7034)
* Add --warnings-as-errors to flatc compiler.

With this option set, flatc will return an error on parsing if
any warnings occurred.

* Add unit test for opts.warnings_as_errors.

* Change explicit option setting to default.
2022-01-25 14:01:16 -08:00
Derek Bailey 9ef1524d3f
Emit include for bfbs-gen-embed (#7031) 2022-01-25 10:43:16 -08:00
Marcin Witkowski aff818cebf
rust: Allow for usage in no_std environment (#6989) 2022-01-20 11:49:02 -05:00
Wouter van Oortmerssen a42e898979
Added verifier alignment checking to table fields (#7018) 2022-01-14 14:39:15 -08:00
Alex E ace4a37f22
[TS/JS] BigInt implementation (#6998)
* BigInt implementation

* Unit test reading long from existing bytebuffer

* Code review
2022-01-06 20:35:37 -06:00
Wouter van Oortmerssen 5b0d491127 Updated FlexBuffers fuzzer 2021-12-14 11:57:42 -08:00
Wouter van Oortmerssen f8148b8dad Made FlexBuffers reuse tracker track types 2021-12-14 11:20:23 -08:00
Derek Bailey a22b1b6267
Prevent shadow with _{{FIELD_NAME}} (#6991) 2021-12-13 21:27:36 -08:00
Derek Bailey c555ee8fac
Add .NET test to github workflows (#6982) 2021-12-13 11:51:27 -08:00
Wouter van Oortmerssen 956d11569e re-enabled FlexBuffer JSON in fuzzer 2021-12-10 15:22:06 -08:00
Wouter van Oortmerssen e367ca32ad
Verifier for FlexBuffers (#6977)
* Verifier for FlexBuffers

* Verifier improvements & fuzzer
2021-12-10 14:59:08 -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