Commit Graph

487 Commits

Author SHA1 Message Date
ll-antn a5ca8bee4d Fix numeric_limits<T>::max() to avoid conflict with windows.h header (#5462) 2019-07-26 09:14:05 -07:00
Paulo Pinheiro de9aa0cdee Add basic Kotlin support (#5409)
* [Kotlin] Add kotlin generate code for tests and add
kotlin test to TestAll.sh

* [Kotlin] Add Kotlin generator

This change adds support for generating Kotlin classes.

The approach of this generator is to keep it as close
as possible to the java generator for now, in order
to keep the change simple.

It uses the already implemented java runtime,
so we don't support cross-platform nor js Kotlin yet.

Kotlin tests are just a copy of the java tests.

* Add optional ident support for CodeWriter

Identation is important for some languages and
different projects have different ways of ident
code, e.g. tabs vs spaces, so we are adding optional
support on CodeWriter for identation.

* [Kotlin] Add Documentation for Kotlin

* [Kotlin] Modify generated code to use experimental Unsigned types.
2019-07-22 16:05:15 -07:00
Alexey Geraskin a752d1b88c [C++] fix static_cast expression (#5441) 2019-07-18 11:51:12 -07:00
Vladimir Glavnyy e304f8c115 Extend the test of MonsterExtra (#5428)
* Extend the test of MonsterExtra

- Extend C++ test of MonsterExtra
- Add conversion of fbs/json NaNs to unsigned quiet-NaN
- Update documentation (cross-platform interoperability)

* Fix declaration of infinity constants int the test
2019-07-08 11:22:56 -07:00
Vladimir Glavnyy 7a63792929 Remove unused variables (#5382)
- Fix GenerateTextFromTable (aliasing typo)
- Fix unused variable in idl_gen_dart.cpp
- Fix std::string passing (should be non-const value or const-reference)
- Remove unused variables
2019-07-01 11:38:21 -07:00
Andrew Noyes 7d7d796cd0 Fix undefined behavior. Closes #5422 (#5423)
* Fix undefined behavior. Closes #5422

* Move check into callers of make_space
2019-06-27 14:11:31 -07:00
Adrian Perez 5479adc80f Fix for FLATBUFFERS_PREFER_PRINTF writing zero-length strings (#5418) 2019-06-27 09:23:13 -07:00
svenk177 e635141d5b Add support for fixed-size arrays (#5313) 2019-06-18 00:15:13 +02:00
Vladimir Glavnyy 0d2cebccfe Add FLATBUFFERS_COMPATIBILITY string (#5381)
* Add FLATBUFFERS_COMPATIBILITY string

- Add a new __reset method NET/JAVA which hides internal state

* Resolve PR notes

* Use operator new() to __init of Struct and Table

* Restrict visibility of C# Table/Struct to internal level
2019-06-17 19:16:21 +02:00
John Luxford a80db8538c [C#, Java, C++] Fixes issue #5399 by always including namespaces (#5404)
* [C#] Fixes issue #5399 by always including namespaces

* Updated tests for code generator changes

* Fixed 'As' method names
2019-06-14 17:47:07 +02:00
Alexander Gallego bc7ede8fb3 c++: Add command line option to add extra includes to gen files (#5360)
* c++: Add command line option to add extra includes to gen files

Fixes #5351
We have an ability to pass custom types for strings, allocators, etc
but have no way to tell the generator to include the classes in gen code

* c++: remove std::strtok for std::string methods. passes msvc compile

* generate_code.sh: add --cpp-includes to the test gen script

* tests:generate.bat: update code gen scripts w/ --cpp-includes

* cpp: use command line parsing for extra includes

s/--cpp-includes/--cpp-include/g
Simplify command line parsing of includes by using a std::vector.

* cpp: idl.h: move std::vector for cpp_includes as the last member

msvc does not understand initalization list on our CI server

* cpp:msvc: CI fails on for-range loops

* cpp:codegen: fix error reporting on flatcc

* as per code review: remove unwated --cpp-include in the
tests/generate_code.{sh,bat}
2019-05-31 13:43:30 -07:00
emkornfield 79f0df3dfc [C++] Fix Undefined behavior for zero length vectors (#5355)
* Fix Undefined behavior for zero length vectors

* Change fix for UBSan
2019-05-30 16:13:34 -07:00
Siarhei Fiedartsou 8d86b5347f Add support for IAR compiler (#5347) 2019-05-16 11:56:22 -07:00
mmoscicki2 39bd667fd0 Fix reverse_iterator in Vector and tests (#5344)
Before this commit tests for iterators passed, even if the code inside
the loop has not been executed.
2019-05-16 11:49:01 -07:00
iceboy b56d60f058 [Go] Generate imports with fixed order (#5340)
* use fixed order for golang imports

* grumble
2019-05-13 10:10:14 -07:00
Vladimir Glavnyy 107c08988a Set default CRTReportMode for the `flatc` target (#5336)
* Set default CRTReportMode for the `flatc` target

* Add util.cpp to GRPC test target

* Fix path to util.h
2019-05-09 10:10:10 -07:00
Vladimir Glavnyy f9ebfcb9c4 Make Monster's Color unsigned (#5318)
- update C++ monster_test::Color to unsigned type
- update Go Color:ubyte in the go_test.go
- add workaround for unsigned enum in java test
- sync generate.bat and generate.sh
2019-05-09 10:07:38 -07:00
Vladimir Glavnyy b8ef8c1521 Fix issues with uint64 enums (#5265)
* Fix issues with uint64 enums

- hide the implementation of enums from code generators
- fix uint64 the issue in the cpp-generator
- fix #5108
- new tests
- enums with bit_flags attribute should be unsigned

* Refine objectives of EnumDef's FindByValue and ReverseLookup methods

- move EnumDef::ReverseLookup implementation to idl_parser.cpp
- fix typos

* Make the IsUInt64 method private
2019-05-02 13:57:58 -07:00
Wouter van Oortmerssen 9e7e8cbe9f Bumped version to 1.11.0
Change-Id: I0c87ad2cf8f8768cf40c5b7abea0add087a5518a
2019-04-24 11:34:53 -07:00
Vladimir Glavnyy dd6daa709b Part of #5265, neutral changes (#5281) 2019-04-08 10:05:50 -07:00
Anthony Liot 249f3b3714 Add method GenerateTextFromTable issue #5249 (#5266)
* Create a function GenerateGenerateTextFromTable in order to create a json from any Table

Signed-off-by: Anthony Liot <anthony.liot@gmail.com>

* Update the test to failed if loadfile or parser return false

Signed-off-by: Anthony Liot <anthony.liot@gmail.com>

* Fix snake_case name typo + space before &/*

Signed-off-by: Anthony Liot <anthony.liot@gmail.com>

* use auto

Signed-off-by: Anthony Liot <anthony.liot@gmail.com>

* Use clang-format on the added code

Signed-off-by: Anthony Liot <anthony.liot@gmail.com>
2019-04-05 11:51:29 -07:00
Nikolay Kuznetsov 4cbff97c43 Fix a warning on compiling with clang (#5258) 2019-03-25 12:06:00 -07:00
Wouter van Oortmerssen 02e73e1ae9 Further fixes to make minireflect compatible with old behavior.
Change-Id: I92c257ec4ab4a0cf4676bd98523b766ce25bf4f6
2019-03-21 15:08:04 -07:00
Wouter van Oortmerssen fd51fadaac Fixed vector_delimited excluding delimiter
Change-Id: I3e758d44b9845d6df91332bb609b4b7ad88659ac
2019-03-18 12:07:36 -07:00
Wouter van Oortmerssen 11198f10f5 Fixed shadowing warning in older gcc for vector_delimited
Change-Id: Ia4d56a5eb086f86eb5d1ad6ddae64e4a51bf3aa3
2019-03-18 10:03:43 -07:00
Wouter van Oortmerssen 3b23ff18ea Made ToStringVisitor backwards compatible with older behavior.
This to support code that relied on tables being multiline,
but not vectors.

This behavior was changed in:
b1a925dfc2 (diff-c45c8fbffbc64f7ff4aa2978612b10d8)

Change-Id: I4c95471b643b2b3fab95e06b1294e19d686b492c
2019-03-14 12:00:44 -07:00
Wouter van Oortmerssen ca68d8b043 Disabled constexpr for hashing functions.
This was incompatible with -Wc++98-c++11-compat on some platforms,
due to local variables in the function.

Change-Id: Idef510c2cefe944eef2e0656f5a219c2158063e6
2019-03-11 14:02:20 -07:00
Vladimir Glavnyy 407fb5d537 Narrows template ascii routines to prevent a possible signed overflow in generic code. (#5232) 2019-03-11 10:26:28 -07:00
Wouter van Oortmerssen eb2a81f73d [C++] Object API: document custom string type requirements,
implement better custom string type constructor alternative
for Unpack() and fix bug with vector of custom string types
in Pack().

Squashed commit of the following:

commit e9519c647e
Author: Luca Longinotti <luca.longinotti@inivation.com>
Date:   Tue Mar 5 18:24:49 2019 +0100

    tests: regenerate code, reverts change to CreateVectorOfStrings().

commit 117e3b0679
Author: Luca Longinotti <luca.longinotti@inivation.com>
Date:   Tue Mar 5 18:15:05 2019 +0100

    idl_gen_cpp.cpp: move clang-format on/off outside of declaration, so they are kept properly aligned automatically.

commit 4791923806
Author: Luca Longinotti <luca.longinotti@inivation.com>
Date:   Tue Mar 5 18:11:40 2019 +0100

    idl_gen_cpp.cpp: full clang-format run with provided Google format file, enforce 80 lines width.

commit 2f0402f9ff
Author: Luca Longinotti <luca.longinotti@inivation.com>
Date:   Tue Mar 5 18:09:32 2019 +0100

    CppUsage: address requested changes.
    idl_gen_cpp.cpp: fix formatting, keep CreateVectorOfStrings for normal string cases.

commit 371d4e0b79
Author: Luca Longinotti <luca.longinotti@inivation.com>
Date:   Fri Mar 1 16:35:29 2019 +0100

    Fix compile error with a vector of non-std::strings. CreateVectorOfStrings() expects a vector of std::string types, but that's not always the case.

commit 92b90d7f0f
Author: Luca Longinotti <luca.longinotti@inivation.com>
Date:   Fri Mar 1 16:15:36 2019 +0100

    Document requirement for custom string types to implement empty() and be constructible from std::string.
    Add new option --cpp-str-flex-ctor to construct custom string types not via std::string, but (char * + length).

commit 28cb2e92d5
Author: Luca Longinotti <luca.longinotti@inivation.com>
Date:   Fri Mar 1 14:31:17 2019 +0100

    idl_gen_cpp.cpp: clang-format run, to better separate changes in content from formatting.

Change-Id: I4887ba2f2c632b9e7a8c938659b088cd95690870
2019-03-11 09:42:02 -07:00
Wouter van Oortmerssen 71628dad0d Fixed vector of union JSON parsing.
This for some reason never had a test case, and was broken.

Change-Id: If832f5eb8b6c5ba8a75257464892634b38719c55
2019-03-07 15:05:00 -08:00
Marcus Comstedt 1b9d1b0110 IterateValue: Use ReadScalar instead of unportable reinterpret_casts (#5209)
This fixes the testcase MiniReflectFlatBuffersTest.
2019-02-25 21:45:11 +01:00
Brian Wellington 6e2d530d61 Fix incorrect code generation on Solaris Sparc. (#5208)
On Solaris Sparc, calling NumToString() with a char called the primary
version, not the signed char or unsigned char specializations, which
caused integer to string conversions to be missed.
2019-02-25 21:41:31 +01:00
Wouter van Oortmerssen 9bf9b18f0a Added -Wc++98-compat-extra-semi
And fixed 2 more extra semi-colons.

Change-Id: I1ee08e5b2f67cd0c886847c05cd4d63cfcafec3e
2019-02-25 11:42:37 -08:00
Wouter van Oortmerssen 537c6ec1e6 Added -Wextra-semi to Clang build.
Also fixed warnings this generated.

Change-Id: If3607907b2dd609f854b7b81225d9cf66af75a60
2019-02-25 09:14:56 -08:00
Brian Wellington a1f14005ab Fix big-endian build. (#5205)
For some reason, Offset<T> is being considered a scalar, which
causes EndianSwap to be passed an Offset<T>.  This doesn't work,
as it does not support types with non-trivial constructors.  This
change adds an overload to WriteScalar(), which works around this.
2019-02-22 01:50:05 +01:00
bwelling bb58442054 Improve endian detection. (#5204)
Add support for using __BYTE_ORDER__, to support platforms where g++
doesn't explicitly define __BIG_ENDIAN__, like Solaris Sparc.
2019-02-21 22:45:11 +01:00
Gabriel Nützi e1defaae5e Add flag to make short names in JS/TS. (#5152)
* Add flag to make short names in JS/TS.

* Synced all missing docs in Compiler.md <-> flatc.cpp.

* Review changes.
2019-02-11 21:34:10 +01:00
iceboy 60e94cf083 Implement (shared) attribute for C++ (#5157)
* Implement native_shared attribute for C++.

Fixes #5141. See also #5145.

* Refine comment in idl.h

* Also refine docs

* Revert "Also refine docs"

This reverts commit 09dab7b45c.

* Also refine docs again.

* grumble
2019-02-11 20:53:45 +01:00
Wouter van Oortmerssen cf47f27164 Turn on -Werror=unused-private-field for Clang.
Change-Id: Ibabc1456baf190eba191ebe0b81e3d73a4acc98f
2019-02-11 09:55:48 -08:00
Wouter van Oortmerssen cc7f9b89f3 Made FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE #ifdef out less
This is to protect against cases where part of a project is
compiled with or without this flag, making for very fragile
and hard to find bugs, such as sizeof(Verifier) changing.

Change-Id: I01c895cdc5b44f860e4b0b9c9613bff1983e2b9d
See: https://bugs.chromium.org/p/chromium/issues/detail?id=929847
2019-02-07 16:34:25 -08:00
Jon Kunkee 4d98faa515 Only use __movsb on architectures that support it (#5147)
With the introduction of Windows 10 on ARM (ARM64), code that assumes
that Windows targets are always x86 or x86_64 targets needs to be
updated.

The hot function ReadUInt64 has been optimized in MSVC builds using the
compiler intrinsic __movsb. Since this does not exist on ARM64 Windows,
this change uses the pure C++ path that other platforms use instead.
2019-02-04 18:57:34 +01:00
Henry Lee d8210d5a83 Make changes on the make_unsigned type trait (#5136)
Fix a typo in the static assert message in `make_unsigned`

Support more specifications for `make_unsigned`
2019-01-28 17:31:58 -08:00
Vladimir Glavnyy 7d3930a2fd Repair `fallthrough` was broken by d4493165 (#5115) (#5139)
- GCC: fixed broken `fallthrough` (checked with 7.3 and 8.2)
- Clang: added `fallthrough` support
- Clang: added `-Wimplicit-fallthrough` checking
2019-01-28 10:16:12 -08:00
find 347dba8501 delete zero width space characters <U+200B>'s to avoid MSVC warning C4819 (#5133) 2019-01-24 15:02:48 -08:00
Vladimir Glavnyy fcacb46d01 Replace deprecated Vector::Length() with Vector::size() (#5131)
- enable FLATBUFFERS_ATTRIBUTE if C++17 or higher
2019-01-24 13:33:19 -08:00
Vladimir Glavnyy 3f388ec747 Repair MSVC-CRT leakage detector and enable this detection with Appveyor-CI (#5105) 2019-01-24 13:30:11 -08:00
Henry Lee c2f40c37b2 [C++]Support reverse iterator in Vector (#5128)
* Add `const` keyword to the `operator-(const uoffset_t &)` function in
`VectorIterator`

* Support reverse iterator in Vector

Introduced a new VectorReverseIterator type. We cannot directly use
`std::reverse_iterator<VectorIterator>` because the signature of
`operator*` and `operator->` in the VectorIterator class are not
standard signatures.

Also added `rbegin()`, `rend()`, `cbegin()`, `cend()`, `crbegin()`
and `crend()` in the Vector class.
2019-01-24 13:24:01 -08:00
Vladimir Glavnyy d44931656a Fix high certainty warnings from PVS-studio (#5115)
* Fix high certainty warnings from PVS-studio

- Introduced FLATBUFFERS_ATTRIBUTE macro to use [[attribute]] if modern C++ compiler used

* Update the note about __cplusplus usage in the MSVC
2019-01-17 09:49:27 -08:00
cor3ntin 7c94ff6c30 Reference::ToString should be const (#5118) 2019-01-14 09:39:58 -08:00
Vladimir Glavnyy 4fa4d36706 Add default NaN/Inf to C#, Java, Python (#5107)
* Add default NaN/Inf to C#, Java, Python

* Python NaN/Inf test added

* Remove MSVC2010/13 dependent code
2019-01-14 09:23:42 -08:00