Commit Graph

256 Commits

Author SHA1 Message Date
tira-misu 9fca5e4f42
Add flatc option to inhibit all warnings #6005 (#6301)
* 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

* Add option --no-warnings to inhibit all warnings

* Fix order of member initialization

* Add documentation for --no-warnings
2020-12-10 14:03:53 -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
Casper 338393f854
Documentation updates for Optional Scalars (#6014) (#6270)
* Documentation updates for Optional Scalars

* Updated Support

* Reword stuff

* s/NULL/null

Co-authored-by: Casper Neo <cneo@google.com>
2020-11-24 14:05:39 -05:00
Austin Schuh e58c182443
Add --require-explicit-ids to require explicit ids (#6277)
* Add --require-explicit-ids to require explicit ids

We just got bit by a well intentioned developer forgetting that field
order by default is the field index.  3 people missed it in review.

I'm looking at ways to make it harder to mess up.  We are requesting
that developers explicitly id all fields in tables.  Automatic (opt in
for others) enforcement of this will help the effort succeed.  This
patch adds a command line flag which lets the user require ids on all
fields in tables.

* Added docs to Compiler.md as well
2020-11-19 17:16:45 -08:00
Kelvin Hu 25eba6f35f
fix typo (#6280) 2020-11-19 09:08:52 -08:00
astange 4ec5e8db90
[C++] Add option to not generate direct copy methods. (#6166)
* Add option to not generate direct copy methods.

The direct copy methods generated by flatc utilize std::vector which isn't allowed on some embedded systems. Permit users of the compiler to not generate these methods so they don't have to be stubbed out.

* Update docs for no-cpp-direct-copy option.
2020-10-12 12:25:10 -07:00
Conan Chen 0bdf2fa156
[C#] Fix and improve project files (#6142)
* [C#] Fix and improve project files

* "net35" target included for Unity 5
* "net46" target included for Unity 2017
* "netstandard2.0" target included for Unity 2018 and general use
* "netstandard2.1" target included for Span<T> support

Included project properties for defining UNSAFE_BYTEBUFFER, BYTEBUFFER_NO_BOUNDS_CHECK, and ENABLE_SPAN_T conditional compilation symbols.

* Add documentation on building for C#
2020-09-28 11:56:59 -07:00
Derek Bailey ab139d6bea
Revert "[C#] Fix and improve project files (#6116)" (#6130)
This reverts commit 750281630b.
2020-09-23 13:14:51 -07:00
Conan Chen 750281630b
[C#] Fix and improve project files (#6116)
* [C#] Fix and improve project files

* "net35" target included for Unity 5
* "net46" target included for Unity 2017
* "netstandard2.0" target included for Unity 2018 and general use
* "netstandard2.1" target included for Span<T> support

Included project properties for defining UNSAFE_BYTEBUFFER, BYTEBUFFER_NO_BOUNDS_CHECK, and ENABLE_SPAN_T conditional compiler constants.

* Add documentation on building for C#
2020-09-21 09:32:59 -07:00
mustiikhalil 89435303b7
[Swift] Migrates struct write APIS to write directly to the buffer (#6093)
* Migrates struct write APIS to in place APIS

* Fixes indentation in grpc swift
2020-09-17 17:10:59 +03:00
mugisoba 6cea45dcd3
fix c# json serializer commandline argument docs (#6104) 2020-09-09 15:02:24 -07:00
Yoon Kyong Sik e86d5b8e97
[Kotlin] Attach JvmStatic annotation to each method in companion object (#6052)
* Attach JvmStatic annotation to each method of companion object

Kotlin does not have static accessor so companion object used instead of static.
It's so natural. But when use kotlin companion object methods on java it is very inconvenient.
```java
GeneratedClassByFlatBuffer.Companion.someMethod()
```

If use @JvmStatic annotation it can be shorten like below.
```java
GeneratedClassByFlatBuffer.someMethod()
```

* Formatting by Idea Google C++ style

* Add comments - Commit for missing cla

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Add comments - Commit for missing cla

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Reset code formatting except modified lines

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Pass missing flag to validateVersion method

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Add annotations to missing method in companion object

* addVector
* createVector
* endVector
* tableCreator

And also I tried add compiler option for generate annotation who don't like this operation.

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Modify unmatched option name in compiler usage

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Add missing operation for finishSizePrefixed and finishStructBuffer method.

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Add compiled example with --kotlin-gen-jvmstatic option.

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Fix Compiler.md

Change option name from --gen-jvm-static-annotation to --kotlin-gen-jvmstatic

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Use IDLOptions reference instead of bool parameter.

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Change option name - kotlin_gen_jvmstatic to gen_jvmstatic

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Use IDLOptions reference instead of bool parameter and missing process @JvmStatic as suffix.

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Add code generation for --gen-jvmstatic option

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Miss typo directory for including.

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Miss typo variable suffix for including.

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Fix camel case to snake case.

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Rollback generate code for gen_jvmstatic option.

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Delete generated test files.

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* add missing new line at end of file.

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

* Remove generated test file by command line.

Signed-off-by: Yoon KyongSik <sam1287@gmail.com>

Co-authored-by: sam <sam@jennifersoft.com>
2020-08-18 09:44:43 -07:00
Dimitri Mitropoulos 9abb2ec2cc
TypeScript/JavaScript docs improvements (#5984)
* use correct language formatter for TypeScript examples

* fixes typo in JS/TS copied from PHP (apparently)

the variables are not named with a prefixed `$`

* fixes bizarre line breaks in markdown examples

* fixes snake case typo to fit JS/TS conventions

* makes example of Uint8Array usage explicit

* removes random extra lines between language blocks

* adds simple example for writing to file in node

* typo: flabuffers => flatbuffers

* adds (previously missing) code blocks to TypeScript code block

* adds context about where `monster_generated` comes from

to the uninitiated, a bit of help like this is welcome
2020-06-18 10:23:32 -07:00
mustiikhalil 2e57d80b13
[Swift] Internal library improvements (#5965)
* Moves addition to overflow addition in swift by using &+

Moves code to use Int instead of UInt32 & fixes functions

Updates swift performance to great

Updated version to 0.5.2

Updated swift package version to 5.2

Updated docker to swift 5.2

Removed all none & arithmetic operations

* Small refactoring
2020-06-18 10:14:38 -07:00
laurens-dg cfc7753a4c
[Doc] Added missing letters to compiler options (#5976)
These are correct in the help section of compiler, but missing some letters here.
2020-06-18 10:02:00 -07:00
Dimitri Mitropoulos 24ad35709d
[docs] typo: updates monsterdata.json to be valid json (#5978)
* updates monsterdata.json to be valid json

the same monster.json file was not valid json

* updates reference to monsterdata.json in docs to also be valid json
2020-06-17 22:35:24 -07:00
Carol (Nichols || Goulding) f94e6c84e0
Small tutorial improvements - documentation only (#5894)
* Use code formatting for a code snippet

* Minor grammar, spelling, and Markdown fixes
2020-05-07 12:15:11 -07:00
Wouter van Oortmerssen 40ba170c94 Fixed text in internals doc that implied structs can be root 2020-04-23 09:28:22 -07:00
mustiikhalil cb4d0f72e3
[Swift] Object API support (#5826)
* Adds Object-api support to swift

* Fixed indentation issues

* Removed indentation within namespaces
2020-04-13 09:28:56 -07:00
Khoi Dinh Trinh 003e164057
[TS] Add Obj API (#5788)
* added basic code

* backup work

* got class property to work

* backup progress

* implementented fmt for creating code

* added docs for genFieldUtils

* back up work

* added base helper js func

* added union js code

* added unpackTo and base for pack

* added pack code

* added null check for packing struct list

* passes compile test

* fixed some spacing of generated functions

* added annotations for constructors

* added obj api unpack test

* tested pack to work

* merge branch

* separated js and ts test

* fixed union signature to include string

* fixed generator to support string union

* hardcoded fb builder name

* refactored struct vector creation

* work around createLong

* handle default value in constructor

* update typescript docs

* added notes about import flag

* fixed formatting stuffs

* undo TypescriptTest change

* refactored fmt

* updated generated code

* remove ignoring union_vector for js

* revert changes for .project

* revert changes for package.json

* don't generate js in ts test

* fixed android project file

* removed unused js function

* removed package-lock.json

* adjust createObjList to new signature

* changed regex to callback style

* fixed package.json

* used existing func for generating annotation

* changed ternary to !!

* added return type for lambda

* removed callback style for obj api generator

* fixed js file indentation

* removed unused header

* added tests for string only union

* handle string only union and refactor union conv func

* updated generated ts files

* renamed union conv func

* made js test create files like other languages

* removed union string only handling

* don't allow null in createObjectOffsetList

* updated generated ts code

* changed the line that triggers Windows build errors

* hopefully fix CI error
2020-04-09 09:53:16 -07:00
Meng Yang 21cf300f4c
fix cpp usage markdown error (#5845) 2020-04-09 09:38:58 -07:00
Vladimir Glavnyy 90f3b8e8c7
Fix `float_constant` definition in './doc/Grammar.md` (#5828) 2020-03-23 09:51:57 -07:00
Yurii Nakonechnyi c4231c3cb9
Updated doxyfile - added missing files (#5824)
Added missing Java/C#/Switft files - that fixes references to them. Removed non-existent "JavaCsharpUsage.md".
2020-03-20 10:13:47 -07:00
Ekene Madu 9657df184e
Update Grammar.md (#5820)
* Update Grammar.md

Some consistency fixes to the grammar file

* Some more minor fixes to Grammar.md

* Update Grammar.md
2020-03-20 10:12:23 -07:00
mustiikhalil 3e9ac3cff9
[Scripts] Adds swift to generated code (#5806)
* Moved swifttest.sh code generator to generate_code + fix issue in ghpages

* Fixes small issue with cocoapods documentation
2020-03-16 11:55:59 -07:00
Myrice 9954e09ab7
[C++] Generate code for vector force_align attribute. (#5796)
* [Flatbuffer] Generate code for force_align with CreateXDirect and Pack functions.

* Fixed Visual Studio 10.0 compile error for std::to_string.

* Fixed Visual Studio 10.0 compile error for std::to_string.
2020-03-12 08:32:29 -07:00
Wouter van Oortmerssen 4749e77b0e Fixed docs on how to obtain parser error.
Change-Id: Ib3ffbdf51ef6af1f5c8267b84b84dceed9d4a838
2020-03-02 12:16:02 -08: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
mugisoba 173e10fdf1
[C#] support Json Serialization (#5752)
* support json serialization

* fix invalid json format.
* string must be written with double quotes.
* remove commma after the last object member.

* fix indent

* Revert "fix invalid json format."

This reverts commit d6820ed50c.

* quated string value.

* add cs-gen-json-serializer flag.

* fix preprocessor indent

* ENABLE_JSON_SERIALIZATION -> ENABLE_JSON_SERIALIZATION_TEST

* share TestBuffer method

* remove ENABLE_JSON_SERIALIZATION

* remove duplicated test data

* [windows] add nuget restore and copy test data.

* [docker mono] share msbuild settings with windows. add nuget restore and copy test data.

* add some note for json api.
2020-02-10 17:43:36 -08:00
mugisoba 7418d85872
[C#] support Object API (#5710)
* [C#] support Object API

* fix sign-compare

* fix indent

* add new line before for loop.

* using auto whenever possible

* reduce the amout of blank lines.

* wip: support vectors of union

* done: support unions of vectors

* set C# version to 4.0
* remove null propagation operator
* remove auto property initializer
* remove expression-bodied method
* remove pattern matching

* add Example2 to NetTest.sh

* separate JavaUsage.md and CsharpUsage.md from JavaCsharpUsage.md

* add C# Object based API notes.

* support vs2010.

* remove range based for loop.

* remove System.Linq

* fix indent

* CreateSharedString to CreateString

* check shared attribute

* snake case
2020-01-30 10:18:28 -08:00
mustiikhalil c580fa284c Adds min and max, comments, and all of swift's keywords + fix docs (#5737) 2020-01-27 10:05:41 -08:00
Phoebe bab2b0db48 Add vcpkg installation instructions (#5732)
* Add vcpkg installation instructions

* Update comments
2020-01-23 15:46:25 -08:00
mustiikhalil a4b2884e4e Added create function for swift (#5707)
Fixed the create functions and updated the test cases in swift

Removes unneeded code

Updated documentation
2020-01-13 12:34:06 -08:00
mustiikhalil 04d80f255d [Swift] Swift implementation 🎉🎉 (#5603)
* Implemented the swift version of Flatbuffers

Implemented serailzing, reading, and mutating data from object monster

Fixes mis-aligned pointer issue

Fixes issue when shared strings are removed from table

Adds swift enum, structs code gen

Fixed namespace issues + started implementing the table gen

Added Mutate function to the code generator

Generated linux test cases

Fixed an issue with bools, and structs readers in table writer

Swift docker image added

Updated the test cases, and removed a method parameters in swift

Fixed createVector api when called with scalars

Fixed issues with scalar arrays, and fixed the code gen namespaces, added sample_binary.swift

Cleaned up project

Added enum vectors, and their readers

Refactored code

Added swift into the support document

Added documentation in docs, and fixed a small issue with Data() not being returned correctly

Fixes Lowercase issue, and prevents generating lookups for deprecated keys

* Made all the required funcs to have const + removed unneeded code + fix lowercase func

* Removed transform from lowercased and moved it to function

* Fixes an issue with iOS allocation from read

* Refactored cpp code to be more readable

* casts position into int for position

* Fix enums issue, moves scalar writer code to use memcpy

* Removed c_str from struct function

* Fixed script to generate new objects when ran on travis ci: fix

* Handles deallocating space allocated for structs

* Updated the test cases to adhere to the fileprivate lookup, no mutation for unions, and updated the names of the vector functions
2020-01-09 12:12:10 -08:00
emkornfield 718351831d Document JSON compatibility guarantees. (#5704)
https://github.com/google/flatbuffers/issues/5688
2020-01-09 10:56:34 -08:00
Wouter van Oortmerssen 31f8799083 Minor doc updates: FlexBuffers C#, Discord, CppUsage.
Change-Id: Ie34ff580eb2f41ff35f85271b10865f4a14d0dca
2019-12-26 12:36:41 -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
cryptocode a8e800bd7c Add --force-empty-vectors option (#5653)
The rationale for this option is that JSON clients typically want empty arrays (i.e [] in the JSON) instead of missing properties, but not empty strings when the value isn't set.
--force-empty is kept as-is, i.e. it will force both empty strings and vectors.

Closes #5652
2019-12-05 17:33:45 -08:00
lu-wang-g 65f8703572 Flatbuffers Python Object API (#5616)
* Flatbuffers Python Object API

Implement the logic to generate the Python object API that can
unpack the data from a buf class into an object class, and pack
the data of an object class to a buf class.

* Fix the build issues

Remove unused parameters and replace auto in the for-loop statement
with std::string to make it compatible with VS2010.

* Fix the build issues.

* Add support for Array type

Added logic to handle Array type in Python Object API. Updated the
generated code accordingly.

* Fix the old style casting from int to char

* Fixed another conversion from int to char

* Fixed the import for typing

Importing typing may cause errors when a machine do not have the
moduel typing installed. This PR fixes the issue by guarding
"import typing" with the "try/except" statement.

* Fix issue of iterating the vector of import list

* Update the generated examples using generate_code.sh

* Fix the import order for typing

The import list was stored in unordered_set, so that each generated
codes may have different import order. Therefore, it failed in the
consistency test where two generated copies need to have exactly the
same apperance.

* Optimize unpack using numpy

Use numpy to unpack vector whenever it is possible to improve unpack
performance.

Also, added codegen command for Python specificly in generate_code.sh,
because --no-includes cannot be turn on for Python.

* Fix the import order

* Update generate_code.bat for windows accordingly

* Replace error message with pass

Avoid printing error message for every Python2 users about typing.
Replace it with pass.
2019-12-02 14:11:28 -08:00
nilsocket 58e279244c [docs]: add missing semicolon (#5648)
Add missing semicolon for table field.
2019-12-02 14:01:25 -08:00
Paulo Pinheiro b5560fcd52 [Java][FlexBuffers] Improve documentation for FlexBuffers in Java. (#5506)
Also add a FlexBuffer constructor to simplify usage
2019-09-10 10:06:47 -07:00
Wouter van Oortmerssen bd31dd2425 Clarified value reuse in FlexBuffers
Change-Id: Ib771bfa46ccdf38eff25be857b1b73f8b300c649
2019-08-26 14:59:21 -07:00
Jason Monschke da88be05e1 Change deprecated vector Length() to size() in tutorial (#5450) 2019-07-25 11:09:40 -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
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
svenk177 e635141d5b Add support for fixed-size arrays (#5313) 2019-06-18 00:15:13 +02:00
Michael Seifert 4eb3efc221 [flatc][docs] Document rounding behavior of floats in JSON output (#5397)
* [docs] Added an example on how to convert a FlatBuffer binary to JSON
Slightly adjusted section on "Using flatc as a conversion tool".

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>

* [docs] Updated obsolete JSON data in example showing how to convert JSON to FlatBuffer binaries.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
2019-06-12 12:35:39 +02:00
Will Stott a807fa9567 Remove out-dated -S option from the flatc syntax. (#5398)
Looks like it's an older syntax for --strict-json which was long-ago removed in d38b9af243
2019-06-09 20:30:10 +01:00
Ashwin Ramaswami b59a1ca2f8 fix typo (#5384)
* fix typo

* fix typo
2019-06-05 19:24:29 +01: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