Commit Graph

305 Commits

Author SHA1 Message Date
Derek Bailey 01a7bc3c58
Add binary schema reflection (#7932)
* Add binary schema reflection

* remove not-used parameter

* move logic from object API to base API

* forward declare

* remove duplicate code gen that was stompping on the edits

* reduce to just typedef generation

* fixed bazel rules to not stomp

* more bazel fixes to support additional generated files
2023-05-04 16:12:45 -07:00
Wouter van Oortmerssen ed11b08fc9 GenerateText gives text error on failure 2023-05-03 13:03:00 -07:00
Adam Oleksy ab716ee41d
Make JSON supporting advanced union features (#7869)
This change allows user to decode binary with given schema to JSON
representation when schema defines union with struct.

Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-04-26 05:37:06 +00:00
Saman f838017860
Parsing from proto should keep field ID. (fixes #7645) (#7655)
* Parsing from proto should keep field ID. (fixes #7645)

* Fix failed tests

* Fix windows warning

* Improve attribute generation in proto to fbs

* Check if id is used twice. fix Some clang-format problems

* Test if fake id can solve the test problem

* Validate proto file in proto -> fbs generation.

* Fix error messages

* Ignore id in union

* Add keep proto id for legacy and check gap flag have been added. Reserved id will be checked.

* Add needed flags

* unit tests

* fix fromat problem. fix comments and error messages.

* clear

* More unit tests

* Fix windows build

* Fix include problems

* Fake commit to invoke rebuild

* Fix buzel build

* Fix some issues

* Fix comments, fix return value and sort for android NDK

* Fix return type

* Break down big function

* Place todo

---------

Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-02-01 11:17:35 -08:00
Wen Sun 802a3a056a
[C++] Enable using struct and array of struct as key (#7741)
* add unit tests for support struct as key

* make changes to parser and add helper function to generate comparator for struct

* implement

* add more unit tests

* format

* just a test

* test done

* rerun generator

* restore build file

* address comment

* format

* rebase

* rebase

* add more unit tests

* rerun generator

* address some comments

* address comment

* update

* format

* address comment

Co-authored-by: Wen Sun <sunwen@google.com>
Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-01-24 16:37:13 -08:00
Saman 74b5195089
Fix operator==() generated for field of fixed sized array (#7749)
* Fix operator==() generated for field of fixed sized array

* Compare address

* noexcept

* Grammer

Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-01-05 20:11:11 -08:00
engedy 4e396d47bc
Add CI step to build with -DFLATBUFFERS_NO_FILE_TESTS. (#7729)
* Add CI step to build with -DFLATBUFFERS_NO_FILE_TESTS

* Fix cmake syntax

* Further fix cmake argumetns

* Add workaround for unused-parameter.

* Remove build matrix

Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-12-22 08:48:48 -08:00
engedy b47ba1d5ff
Add include guards around DoNotRequireEofTest (#7728)
Guard DoNotRequireEofTest against -Wunused-function on platforms without file tests.
2022-12-21 14:59:34 -08:00
Alex Ames bb9b9dad5f
Fixed the BytesConsumed function, which was pointing slightly ahead. (#7657)
The BytesConsumed function uses the `cursor_` to determine how many
bytes have been consumed by the parser, in case the user of the Parser
object wants to step over the parsed flatbuffer that is embedded in some
larger string. However, the `cursor_` is always one token ahead, so that
it can determine how to consume it. It points at the token that is about
to be consumed, which is ahead of the last byte consumed.

For example, if you had a string containing these two json objects and
parsed them...

    "{\"key\":\"value\"},{\"key\":\"value\"}"

...then the `cursor_` would be pointing at the comma between the two
tables. If you were to hold a pointer to the beginning of the string and
add `BytesConsumed()` to it like so:

    const char* json = // ...
    parser.ParseJson(json);
    json += parser.BytesConsumed();

then the pointer would skip over the comma, which is not the expected
behavior. It should only consume the table itself.

The solution is simple: Just hold onto a previous cursor location and
use that for the `BytesConsumed()` call. The previous cursor location
just needs to be set to the cursor_ location each time the cursor_ is
about to be updated. This will result in `BytesConsumed()` returning
the correct number of bytes without the off-by-one-token error.

Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-11-22 20:11:14 +00:00
Wen Sun eb1abb51ea
Add support for using array of scalar as key field in Cpp (#7623)
* add support for using array of scalar as key field

* update cmakelist and test.cpp to include the tests

* update bazel rule

* address comments

* clang format

* delete comment

* delete comment

* address the rest of the commnets

* address comments

* update naming in test file

* format build file

* buildifier

* make keycomparelessthan call keycomparewithvalue

* update to use flatbuffer array instead of raw pointer

* clang

* format

* revert format

* revert format

* update

* run generate_code.py

* run code generator

* revert changes by generate_code.py

* fist run make flatc and then run generate_code.py

Co-authored-by: Wen Sun <sunwen@google.com>
2022-11-18 11:04:46 -08: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
Even Rouault a22434e2a1
Add missing #include <algorithm> for std::min/std::max uses, and #include <limits> for std::numeric_limits<> (#7624) 2022-11-08 09:36:35 -08:00
Alex Ames a4ff275d9b
Added option to not requires an EoF token when parsing JSON (#7620)
Previously when parsing a JSON representation of a Flatbuffer, the
parser required that the input string contain one and only one root
table. This change adds a flag that removes that requirement, so that
if a Flatbuffer table is embedded in some larger string the parser will
simply stop parsing once it reaches the end of the root table, and does
not validate that it has reached the end of the string.

This change also adds a BytesConsumed function, which returns the number
of bytes the parser consumed. This is useful if the table embedded in
some larger string that is being parsed, and that outer parser needs to
know how many bytes the table was so that it can step over it.
2022-11-03 11:57:46 -04:00
Dominic Battre acc6a20d39
tests/test.cpp contains a couple of tests that are only executed (#7571)
on a subset of platforms. The test calls are guarded via #ifndef
FLATBUFFERS_NO_FILE_TEST.

Embedders of flatbuffers that rely on -Werror,-Wunused-function
compiler flags (like chromium) complain about the exsitence of these
tests in the anonymous namespace.

This CL guards the test definitions as well (not just the test
calls).

Co-authored-by: Dominic Battre <battre@chromium.org>
Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-10-18 12:37:06 -07:00
Denis Blank 72aa85a759
[C++] Rare bad buffer content alignment if sizeof(T) != alignof(T) (#7520)
* [C++] Add a failing unit test for #7516 (Rare bad buffer content alignment if sizeof(T) != alignof(T))

* [C++] Fix final buffer alignment when using an array of structs
* A struct can have an arbitrary size and therefore sizeof(struct) == alignof(struct)
  does not hold anymore as for value primitives.
* This patch fixes this by introducing alignment parameters to various
  CreateVector*/StartVector calls.
* Closes #7516
2022-09-21 11:05:05 -07:00
Derek Bailey bc44fad352
UnPackTo disable merge by default (#7527)
* UnPackTo disable merge by default

* avoid double free in test

* remove merge parameter

* remove shrink to fit
2022-09-13 22:00:01 -07:00
Casper 41d9add7ef
C++: Add option to skip verifying nested flatbuffers (#7489)
* C++: Add option to skip verifying nested flatbuffers

Additionally, add an options struct to the verifier for those
who prefer designated initializers to default arguments. The former
constructor is defined in terms of the latter because in old c++,
having default values for members removes list initialization, making
defining constructors in the other way a lot more challenging to write.

* fixes

* fmt

* formatting, and remove an argument

* fix

Co-authored-by: Casper Neo <cneo@google.com>
Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-08-29 16:25:57 -07:00
sssooonnnggg 6a87427540
[C++] support native_inline attribute for vector of tables (#7479) 2022-08-29 12:48:10 -07:00
Derek Bailey 694add668b
Refactor test.cpp (#7487)
* Add timing command to cmakelist

* Start to split test.cpp. Move flexbuffers tests

* Move monster related tests to own file

* Move parser related tests to own file

* Move json related tests to own file

* Move proto related tests to own file

* moved more functions to parser test

* moved more functions to parser test2

* move monster extra tests to monster test

* move evolution tests to own file

* move reflection tests to own file

* move util tests to own file

* rehomed various tests

* move optional scalars test to own file:

* rehome more tests

* move fuzz tests. Got rid of global test_data_path

* fixes for CI failures

* add bazel files
2022-08-28 16:54:58 -07:00
Derek Bailey b86387442e
Fix typos (#7483) 2022-08-26 14:35:21 -07:00
Paul Harris f7c511957f
Audit and fixups for GCC and Clang (#7212)
Added (for compiler versions that support it):
-Wmissing-declarations
-Wzero-as-null-pointer-constant

Then, fixes to problems identified by the extra warnings
Tested only on GCC 9.4.0

Adjusted the CPP code generator to output nullptr where appropriate,
to satisfy -Wzero-as-null-pointer-constant

Added a lot of 'static' declarations in front of functions,
to satisfy -Wmissing-declarations,
and wrap static function defs in anonymous namespaces.

There are advantages to both anonymous namespaces and static,
it seems that marking a function as static will not publish the name in
the symbol table at all, thus giving the linker less work to do.
2022-08-16 10:48:41 -07:00
Mirko Bonadei 137fec7164
Stop using __has_trivial_copy on recent clang versions. (#7443)
Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-08-15 09:49:59 -07:00
Derek Bailey 44a7dc9995
Define minimum buffer size (#7440)
* add check for zero sized buffers

* Define minimum flatbuffer size
2022-08-14 12:40:57 -07:00
Stefan F 3cc2daa78f
make_span overloads for pointer to vector (#7374) (#7435)
* make_span overloads for pointer to vector (#7374)

* findings from the review

Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-08-14 12:21:55 -07:00
sssooonnnggg 4be605604e
[C++] Set StructDef::has_key property when deserializing from binary schema (#7386) (#7428) 2022-08-12 09:27:17 -07:00
sssooonnnggg 7798be3bb6
avoid zero-as-null-pointer warning (#7423)
Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-08-08 21:32:13 -07:00
Derek Bailey 966362e074
[C++] Vector of Tables equality (#7415)
* Vector of Tables equality

* support nullptr and fix for not being able to use auto in lambda

* use different std::equal overload

* use flatbuffers::unique_ptr

* go back to auto and clang-format fix
2022-08-08 21:22:57 -07:00
Wouter van Oortmerssen ec0129369c Fix FlexBuffers Verifier tracking vectors reuse at wrong offset
See test for an example.
Found in: https://github.com/aardappel/lobster/pull/193
2022-08-05 10:45:01 -07:00
Caleb Zulawski 83a43fc797
Reenable optional json (#7352)
* Revert "Revert "Implement optional scalars for JSON (#7322)" (#7351)"

This reverts commit 9a1913a87a.

* Add optional scalars json to bazel

Co-authored-by: Caleb Zulawski <caleb.zulawski@caci.com>
2022-06-16 09:26:44 -07:00
Derek Bailey 9a1913a87a
Revert "Implement optional scalars for JSON (#7322)" (#7351)
This reverts commit a18ea40d6a.
2022-06-15 00:32:28 -07:00
Caleb Zulawski a18ea40d6a
Implement optional scalars for JSON (#7322)
* Implement optional scalars for JSON

* Add optional scalars JSON test

* Extend JSON optional scalars test to test without defaults

* Fix optional scalars in JSON for binary schema

Co-authored-by: Caleb Zulawski <caleb.zulawski@caci.com>
2022-06-14 18:00:24 -04:00
mustiikhalil 11a1988705
Started implementation for private flags in rust (#7269)
Adds flag to the cpp to fix bad annotations in all the languages

Addresses comments to the PR, and fixes logic for leaking annotations
2022-06-05 23:04:05 +02:00
pkasting 0fe13cb28c
Remove span ConstIterator/cbegin()/cend(). (#7295)
std::span lacks these; make  the flatbuffers STL emulation and tests
match.  This fixes a compile error in C++20 mode when using std::span.

Bug: chromium:1284275
2022-05-10 13:53:38 -07:00
Derek Bailey 7bcd857b87
Specialize CreateVector with std::initializer_list (#7254) 2022-04-19 13:06:50 -07:00
Derek Bailey 6e0e79f24f
Add test for nested buffer verifier (#7252)
* Add test for nested buffer verifier

* switch to base API
2022-04-18 10:20:06 -07:00
Henner Zeller 18bacd3ea5
Expand test to make sure {}-initializers are properly understood by template. (#7242)
Since CreateVectorOfStrings() takes a templated container, make sure that
the default template deduction from just an initializer list will
still work.

Signed-off-by: Henner Zeller <hzeller@google.com>
2022-04-13 14:13:32 -07:00
Henner Zeller 7f663b1204
Allow CreateVectorOfStrings() to work with any string-type. (#7238)
Any string type that is supported by CreateString(), e.g.
const char* or string_view will now also work.

Signed-off-by: Henner Zeller <hzeller@google.com>
2022-04-11 17:02:19 -07:00
Derek Bailey 14615699fa
Started to migrate to target_compile_options (#7222)
* Started to migrate to target_compile_options

* combined compile options together. Added Mac CI builds

* remove arm build (not supported). Fixed old-style-casts

* moved to using a ProjectConfig interface library to specify options

* remove the explicit CMAKE_CXX_STANDARD
2022-04-06 13:25:43 -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
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
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 faadbc10ea
Add CreateVector overload to accept array like (#7095) 2022-02-09 22:16:46 -08:00
Derek Bailey bc901436db
clang format on codebase (#7058) 2022-02-01 11:23:18 -08: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
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
Wouter van Oortmerssen f8148b8dad Made FlexBuffers reuse tracker track types 2021-12-14 11:20:23 -08:00
Wouter van Oortmerssen e367ca32ad
Verifier for FlexBuffers (#6977)
* Verifier for FlexBuffers

* Verifier improvements & fuzzer
2021-12-10 14:59:08 -08:00
Derek Bailey e89de4411d
clang-all (#6941) 2021-11-19 17:01:48 -08:00
Taiju Tsuiki 587bbd49a7
[C++] Fix compile failure on Object API union construction for struct member (#6923)
* Add dedicated traits to Object API version of unions.

* Add suppression for unused parameters on unions of structs.
2021-11-18 10:55:11 -08:00