Commit Graph

238 Commits

Author SHA1 Message Date
Casper 86401e078d
Default strings and vectors: Parser + Rust support (#6421)
* Fix tests.cpp

* Parser support for vector/string defaults

* tests and default empty vectors

* addressed comments

* Default strings and vectors for Rust

* Tested Rust more_defaults

* git-clang-format

* add more_defaults_test

* fixed vector default

* removed commented out code

* more unreachable

Co-authored-by: Casper Neo <cneo@google.com>
2021-02-12 09:41:10 -05:00
Casper e581013e3d
Refactor FieldDef to model presense as an enum rather than 2 bools. (#6420)
* Define presence.

* Migrate to IsRequired and IsOptional methods

* moved stuff around

* Removed optional and required bools from FieldDef

* change assert to return error

* Fix tests.cpp

* MakeFieldPresence helper

* fmt

* old c++ compatibility stuff

Co-authored-by: Casper Neo <cneo@google.com>
2021-01-25 09:29:43 -08:00
mustiikhalil 786f69b248
Formats cpp code (#6349) 2021-01-22 10:46:53 -08:00
Vladimir Glavnyy 83ce29cc22
[C++, JSON] Fix nullptr access when reading a key with a default value. (#6375)
This commit fixes handling of default and NULL `key` fields in `Parser::ParseVector` (#5928).

The JSON generator updated. It outputs `key` fields even if the `--force-defaults` option is inactive.

Additional test cases for `key` added.
2021-01-07 11:24:59 -08:00
Vladimir Glavnyy e7430bbebd
[idl_parser] Check the range of explicitly set field's id value (#6363)
* [idl_parser] Check the range of explicitly set field's id value

The explicitly set `id` attribute should be a non-negative value of the `voffset_t` type.

* Format FieldIdentifierTest()
2021-01-04 12:33:31 -08:00
Kjetil Østerås f2511d7d49
Renaming infinity variables in test.cpp (#6340)
The infinityf symbol is causing a conflict when building for cygwin. In
the cygwin math.h header there is also a symbol called infinityf. So
this patch is needed to be able to build the flatbuffer tests in a
cygwin environment.
2020-12-17 13:08:23 -08:00
Vladimir Glavnyy 7f33cf682a
[C++] Switch `flatc` to `--cpp-std c++11` C++ code generator (#6306)
Prior to this commit the default C++ code generator was `c++0x`.
A code generated with `c++0x` code-gen might have a vulnerability (undefined behavior) connected evolution of enums in a schema. This UB could break the backward compatibility if previously generated code casts an unknown enumerator to enum type that knows nothing about future enumerators added to the schema.

The main differences between `c++0x` and `c++11`:

- generated enums use explicitly declared underlying type;
- generated object-API tables don't declare default ctor() explicitly, instead of it default data member initializers are generated.

Please use `flatc --cpp-std c++0x` option for backward compatibility with old compilers.
2020-12-07 11:19:36 -08:00
Vladimir Glavnyy c27bc2d76f
[C++] Add ParseJson(), Parser(Parser&&), update fuzzers (#6284)
- add a new method ParseJson to minimize failures during fuzzing
- add default (conditional) move-constructor for Parser
- add a new monster_fuzzer
- switch fuzzers to C++17 and `test/cpp17` generated code
2020-11-23 10:17:44 -08:00
Paulo Pinheiro 1606fb6375
Kotlin test optional enum (#6201)
* Add test for optional enums in Kotlin

* Rename optional_scalars2.fbs into optional_scalars.fbs

Also updated all references in the project to point to
"optional_scalars.fbs" instead of "optional_scalars2.fbs".
2020-10-22 13:36:02 -07:00
Vladimir Glavnyy 04bec23a37
Add Array initialization from struct constructor (#5865) (#6147)
- add flatbuffers::span
- add new constructor for `struct` with `array`
- add some test for flatbuffers::span and 'arrays_test.fbs'
2020-10-12 12:24:18 -07:00
Casper 3359e3042f
Moved C++ to optional_scalars2 and added some tests. (#6162)
* Moved C++ to optional_scalars2 and added some tests.

Also deleted unused optional_scalars_generated.lobster

* Fixed whitespece in C++ gencode & fixed BUILD file

* Moved C++ onto optional_scalars2 in the .bat file

Co-authored-by: Casper Neo <cneo@google.com>
2020-10-07 09:46:09 -07:00
Vladimir Glavnyy bbcc85fd4c
Fix generation of C++ code with Optional<Enum> (#6155) 2020-10-02 10:27:30 -07:00
Mark Nauwelaerts 34d67b425e
Minireflect fixed array (#6129)
* CMakeLists: also really generate optional_scalars as needed by test elsewhere

* [C++] Handle fixed-length array in minireflection

Fixes #6128
2020-09-22 17:57:01 -07:00
Vladimir Glavnyy 8c67b5b129
Add support of Optional<T> scalars to C++ code generator (#6092) 2020-09-18 12:51:17 -07:00
Paulo Pinheiro 6228b66d3d
[Kotlin] Support for optional scalars. (#6115)
More information on #6014
2020-09-17 23:31:51 -07:00
Casper c75ae24293
Optional-ness in reflection (#6097)
* Optional scalars in reflection

* fixed name collision

* Remove code duplicated by merge

Co-authored-by: Casper Neo <cneo@google.com>
2020-09-11 14:20:32 -07:00
Casper 338944d3d9
Rename Nullable scalars to Optional scalars (#6112)
Co-authored-by: Casper Neo <cneo@google.com>
2020-09-10 13:04:36 -07:00
Navin Mohan bb25956f09
Wrap verify file id condition in Check call (#6085)
Run clang-format

Update testcase
2020-08-31 11:32:13 -07:00
Wouter van Oortmerssen f3003e08d0 [Lobster] missed a test 2020-08-18 14:29:44 -07:00
mustiikhalil d76e93f277
adds code gen for optional scalars in swift (#6038)
Adds swift test code

Replaces if statments

Adds swift to supported languages for optionals

Moved std::string to auto

Adds nullable scalars support in object api
2020-07-25 17:59:34 +03:00
Casper 043b52bd4a
Optional Scalars support for Rust (#6034)
* First draft of rust optionals

* Code cleanup around ftBool and ftVectorOfBool

* Tests for Rust optional scalars

* test bools too

Co-authored-by: Casper Neo <cneo@google.com>
2020-07-23 16:30:27 -07:00
Vasyl Gello 2e48c8dd31
tests: Check for both quiet and signaling NaN on mipsel/hppa (#6029)
MIPSEL, MIPS64EL and HP-PA architectures have quiet and
signaling NaNs swapped. The test assumes correct values
for i386 / amd64 but obviously fails on these architectures.
It is documented in many places, like

https://software.llnl.gov/yorick-doc/stdlib/ieee.html :

Warning-- apparently there is no universal standard for what
  constitutes signalling versus quiet NaN
  on MIPS and HPPA architectures, qNaN and sNaN are reversed

https://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html :

  -mnan=2008
  -mnan=legacy

  These options control the encoding of the special
  not-a-number (NaN) IEEE 754 floating-point data.

  The -mnan=legacy option selects the legacy encoding.
  In this case quiet NaNs (qNaNs) are denoted by the first
  bit of their trailing significand field being 0, whereas
  signaling NaNs (sNaNs) are denoted by the first bit of
  their trailing significand field being 1.

  The -mnan=2008 option selects the IEEE 754-2008 encoding.
  In this case qNaNs are denoted by the first bit of their
  trailing significand field being 1, whereas sNaNs are
  denoted by the first bit of their trailing significand
  field being 0.

  The default is -mnan=legacy unless GCC has been configured
  with --with-nan=2008.

The behavior mentioned above causes FTBFS in Debian starting
with 1.12.0:

https://buildd.debian.org/status/fetch.php?pkg=flatbuffers&arch=mips64el&ver=1.12.1%7Egit20200711.33e2d80%2Bdfsg1-0.1&stamp=1594830681&raw=0
https://buildd.debian.org/status/fetch.php?pkg=flatbuffers&arch=mipsel&ver=1.12.1%7Egit20200711.33e2d80%2Bdfsg1-0.1&stamp=1594832647&raw=0
https://buildd.debian.org/status/fetch.php?pkg=flatbuffers&arch=hppa&ver=1.12.1%7Egit20200711.33e2d80%2Bdfsg1-0.1&stamp=1594830726&raw=0

For HP-PA (PA-RISC) there is no way to override the reversal,
and for MIPSEL/MIPS64EL there is no macro defining the '-mnan'
choice, so both variants were added with OR boolean operator.

Signed-off-by: Vasyl Gello <vasek.gello@gmail.com>
2020-07-20 10:18:02 -07:00
Casper 9ecd2e16c2
Flatc parser support for nullable scalars (#6026)
* Parser support for nullable scalars

* Use older C++ features

* use default element

* Add a test for json, flexbuffers, and null

* test comments and names

Co-authored-by: Casper Neo <cneo@google.com>
2020-07-16 13:43:47 -07:00
Derek Bailey 60b6066feb
Add warning to schema parser if field name is not snake_case. (#6005)
* Added code gen for evolution tests back in.

* General generate code and clang format

* Added code gen for evolution tests back in.

* General generate code and clang format

* reran generate_code.sh

* Added code gen for evolution tests back in.

* General generate code and clang format

* Added code gen for evolution tests back in.

* General generate code and clang format

* Enforce snake_case for schema field names

* Switched to basic for loop, Fixed warning message
2020-06-26 11:16:02 -07:00
Alex Ames b124b76258
Removed requirement that enums be declared in ascending order. (#5887) 2020-06-22 17:02:15 -07:00
Liu Liu cc44a44427
[idl_parser] Mark typefield as deprecated (#5958)
* Mark typefield as deprecated

* Add UnionDeprecation Test.

* Update to use evolution schema instead.

* Use --scoped-enums to compile.
2020-06-15 23:18:12 -07:00
bakinovsky-m 988164f6e1
[C++] Got rid of memset's in constructors (#5938)
* [C++] removed array's memsets from struct parametrized constructor

now POD-typed arrays are zero-initialized
and class-typed arrays are default-initialized

* [C++] memset -> zero/default initialization in default constructor

* [C++] Struct-type and array default initialization

* [C++] Newly generated tests

* [C++] forgotten test

* [C++] curly brace by code style

* [C++] test if memory is 0's after placement new

* [C++] memory leak fix

* [C++] simplifying and non-dynamic memory in test

* [C++] code cleanup

* [C++] disable old-compiler warning

* [C++] windows build fix (try)

* [C++] debug-new win build fix
2020-06-01 17:58:52 -07:00
Vladimir Glavnyy 424a473e1f
Schema parser: prohibit declaration of an array of pointers inside structs (#5907)
* Fix issue #5906, Prohibit declaration of an array of pointers inside structs

- idl_parser.cpp: Prohibit declaration of an array of pointers inside structs
- idl_gen_cpp.cpp: Extract GenStructConstructor() method from GenStruct() to simplify future modification
- idl_gen_cpp.cpp: Add assert for checking of Array fields in structs on code-generation stage

* Fix the error 'unused local variable' in release build

* Fix: format the PR code according to coding rules

* Add test-case and fix review notes
2020-05-14 11:39:58 -07:00
Dmitriy Kovalev c37c989ed6
Correct calculation of vector element size (#5831)
Number of elements on the stack shouldn't affect the calculation
of ElemWidth(). Variable 'start' needs to be subtracted from the
loop variable 'i' to make indexing zero-based.

There is an additional unit test to pack nested vectors. Size of
the packed buffer *without* this fix is 798 and only 664 bytes
*with* the fix.
2020-03-26 08:54:52 -07:00
Vladimir Glavnyy 9b034eee12
Fix interpretation of 'nan(number)' by the idl_parser (#5810)
* Parser reject "nan(n)" string as it does with nan(n)

* Adjust scalar fuzzer to ignore '$schema' substrings

- Scalar fuzzer ignores '$schema' substrings at the input
- Added 'scalar_debug' target to simplify research of fuzzed cases

* Improve formatting of './tests/fuzzer/CMakeLists.txt'
2020-03-16 11:59:34 -07:00
Derek Bailey 6ff1898413
Added --filename-suffix and --filename-ext to flatc (#5778)
* Fixed refractoring issue in reflection/generate_code.sh. Also, mv deletes the original file, so I don't need to clean it up manually in that case.

* Added --filename-suffix and --filename-ext to flatc

* Fixed typo and added example generation of suffix and extension for C++

* Removed extra ;

* Removed clang-format block from a region that didn't need it. Fixed an auto format of another clang-format block

* Added docs, fixed pointer alignment, removed suffix test file
2020-03-02 10:15:23 -08:00
sjoblom65 47026ea6ba Added the code to embed the binary schema to the source (--bfbs-gen-embed). (#5701)
* Added the code to embed the binary schema to the source.
This is pulled forward from a old PR #5162 that will be closed.

* Update idl_gen_cpp.cpp

Added a small comment to trigger a new build. The build was failing in a strange location and doesn't look like it has anything to do with the code.

* Moved the EscapeAndWrapBuffer to util.cpp and did some formating.

* One more camelCases removed and renamed some variables.

* wrapped_line_xxx should have been passed as a const reference in the first place.

* Moved the bfbs embed sample to it's own file.

* Missed moving the namespace back.

* Moved the embedded bfbs to test.cpp instead of using a sample.

* Missed adding the generation of embedded bfbs to the build.

* See if this makes the build happier.

* Fixed a in-compatable cpp output of the generated header.

* Did some changes to reflect the code review comments.
1. Update the EscapeAndWrapBuffer to BufferToHexText and fixed a variable name.
2. Moved the include of the embedded binary schema to all the other includes.

* Moved some code to inline the instead of using a local variable.

* Moved the BufferToHexText back to be a inline function in util.h
2020-01-24 14:55:34 -08:00
Vladimir Glavnyy 01189d7edd [C++] Fix for printing of enum in case output_enum_identifiers=1. (#5706)
* Add test-case for testing of the future Color in json (output_enum_identifiers = true)

* Refactoring of idl_gen_text.cpp. Fix for printing of bit-enum with active output_enum_identifiers=1.

* Move  GenerateText implementation into class

* Remove unnecessary code from flatbuffers.h
2020-01-16 14:12:25 -08:00
Michael Beardsworth 21b7061963 (Optionally) add an additional suffix namespace to generated fbs files. (#5698)
This change allows for the generation of fbs files (from proto) that
don't contain name collisions with the protobuf generated C++ code,
allowing both the proto and fbs message types to be linked into the same binary.
2020-01-06 10:00:59 -08:00
Wouter van Oortmerssen c957550511 Removed test proto output.
Change-Id: Iaf64bec068d03dd1b75670e9a28dde7392ebddb5
2019-12-23 12:33:16 -08:00
Vladimir Glavnyy 44bf719883 Add flatc '--cpp_std' switch (#5656)
* Add flatc '--cpp_std' switch and sandbox for C++17 code generator

- Added 'flac --cpp_std legacy' for compatibility with old compilers (VS2010);
- Added experimental switch 'flac --cpp_std c++17' for future development;
- Added C++17 sandbox test_cpp17.cpp;
- C++ code generator generates enums with explicit underlying type to avoid problems with the forward and backward schema compatibility;
- Adjusted CMakeLists.txt, CI and generate code scripts to support of introduced '--cpp_std';

* Fix --cpp_std values: c++0x, c++11, c++17

* Add 'cpp::CppStandard' enum

* Add testing engine into test_cpp17

* Rebase to upstream/master

* Set default '--cpp-std C++0x'

* Fix code generation (--cpp_std C++11) in CMakeLists.txt

- Fix dependency declaration of grpctest target

* Revert --cpp-std for the tests from explicit C++11 to flatc default value (C++0x)
2019-12-23 12:13:48 -08:00
Wouter van Oortmerssen 3e8f15df90 Fix for FlexBuffers FBT_VECTOR_STRING size bit-width.
For details, test.cpp/FlexBuffersDeprecatedTest(), and also
https://github.com/google/flatbuffers/issues/5627

Change-Id: I6e86e1138a5777e31055cfa2f79276d44732efbc
2019-12-23 11:49:59 -08:00
Michael Beardsworth 13c05f4da3 Improve import handling for proto conversion (#5673)
* Keep include prefix when converting from proto.

This change preserves the include prefix when generating flatbuffers
from proto (with FBS_GEN_INCLUDES) defined.

* Improve handling of imports in proto conversion.

Previously, there was no runtime flag to make proto->fbs conversion keep
the import structure of a collection of files. This change makes proto
conversion respect the --no-gen-includes flag and skip the output of
"generated" symbols.
2019-12-23 08:50:29 -08:00
Vladimir Glavnyy c3c32ec942 Fix ambiguity of a type deduction in TEST_EQ macro if arguments have `enum class` type. (#5630) 2019-11-25 12:56:47 -08:00
Derek Bailey 136d75fa65 Changed null checks in test. Removed verifier pointer usage (#5634) 2019-11-21 10:25:31 -08:00
Derek Bailey dda095023d [C++] Adds basic schema evolution tests (#5611)
* Added basic schema evolution tests

* Add BUILD targets for evolution tests. Added to test/generate_code scripts

* Use vector.front() instead of vector.data()

* Added --scoped-enums option for evolution test
2019-11-14 15:44:18 -08:00
Derek Bailey 42c08cbca6 Ran src/clang-format-all.sh (#5617) 2019-11-11 09:29:37 -08:00
Derek Bailey f0f0efe7b8 [C++] Refactor to conform to Google C++ style guide (#5608)
* Automatic refractor of C++ headers to Google C++ style guide

* Automatic refractor of C++ source to Google C++ style guide

* Automatic refractor of C++ tests to Google C++ style guide

* Fixed clang-format issues by running clang-format twice to correct itself. Kotlin was missing clang-format on after turning it off, so it was changed,
2019-11-07 12:22:54 -08:00
Wouter van Oortmerssen 32f47ad247 Fixed JSON parser not sorting vectors of tables/structs with key.
Change-Id: Iacc0c8513af80a736700e6cbaf513ebdf8e3ac89
2019-10-10 15:25:39 -07:00
Vladimir Glavnyy cbdf82e2fb Fix Mutate() methods of Array<scalar/struct> (override 5508) (#5526)
* Draft with Array specialization (#5508)

* Array specialization + SFINAE to fold copy-paste (#5508)

* Add implicit specialization of Array<scalar> and Array<struct> (#5508)

- Tag dispatching is used for implicit specialization
- Array<scalar> and Array<struct> have different iterators and accessors
- Array<scalar> and Array<struct> have different Mutate() methods

* Add implicit specialization of Array<scalar> and Array<struct> (#5508)

- Tag dispatching is used for implicit specialization
- Array<scalar> and Array<struct> have different iterators and accessors
- Array<scalar> and Array<struct> have different Mutate() methods
2019-09-23 09:31:51 -07:00
Wouter van Oortmerssen 917687c7a6 Fixed Reflection Verifier not handling vectors of unions.
Change-Id: Ie94386ff8e10fd2a964bd9155139b50953746a37
2019-09-16 17:48:54 -07:00
Wouter van Oortmerssen f9277e691d Fixed GenerateText not handling vectors of unions.
Change-Id: Ie82abaf178495c4692e7d10be6b4a13f2fa1bee6
2019-09-16 14:44:14 -07:00
Wouter van Oortmerssen 1fbb711324 FlexBuffers: allow any values to be shared.
(see comments in the code).

Change-Id: I5603abb0db436145739653692644bbcfd3c946e3
2019-08-26 14:17:52 -07:00
svenk177 4525c91be3 Fix incorrect padding in arrays of structs (Issue #5484) (#5491) 2019-08-23 10:46:47 -07:00
Alexey Geraskin 2d5315ff0e [C++] remove static_cast expression (#5440)
* [C++] remove static_cast expression

* [C++] Add unit test for native_type usage

* [C++] Add flatc compilation for native_type_test.fbs

* [C++] update CMakeLists to compile native_type_test.fbs properly

* Update BUILD file for bazel

* [C++] Add generated native_type_test_generated.h and fix arguments for flatc according to CMakeList

* [C++] remove "= default" from constructor to support old compilers

* Update BUILD file for bazel, attempt 2

* [C++] Workaround for MSVC 2010 for the issue with std::vector and explicitly aligned custom data types

* Update BUILD file for bazel, attempt 3

* Update BUILD file for bazel, attempt 4

* Update BUILD file for bazel, attempt 5

* Update BUILD file for bazel, attempt 6

* [C++] Workaround for MSVC 2010 for the issue with std::vector and explicitly aligned custom data types Part 2

* [C++] Keep only one optional parameter to compile_flatbuffers_schema_to_cpp_opt

* native_type_test.fbs style corrected

* [C++] Code style modifications

* [C++] Fix flatc arguments in CMakeLists

* [C++] Remove --gen-compare from default parameters for flatc in CMakeLists

* [C++] Change Vector3D fields from double to float, to have alignment eq. 4 (to support MSVC 2010), plus minor review fix

* [C++] Remove one more #if !defined

* [C++] Restore version with correct static_cast, add the same fix for SortedStructs

* Revert "[C++] Restore version with correct static_cast, add the same fix for SortedStructs"

This reverts commit d61f4d6628.

* [C++] Fix Android.mk
2019-08-01 14:31:48 -07:00