Commit Graph

1413 Commits

Author SHA1 Message Date
jsanmiya 4f4495a693 Merge pull request #4148 from gbeili/vector_unions
C++ Union Vector
2017-01-24 14:33:32 -08:00
Bei Li 68bbe983e9 Union Vector 2017-01-24 11:52:36 -08:00
Florin Pățan bbef92c17d Reword comment so that code editors can mark deprecation correctly (#4147) 2017-01-23 13:40:50 -08:00
Koichi Shiraishi 25c884158f
go: fix unknown field 'UOffset' to 'Pos'
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
2017-01-22 20:16:52 +09:00
Wouter van Oortmerssen 3f936c5655 More native code gen functionality.
Allow tables to be mapped to native types directly.  For example, a table
representing a vector3 (eg. table Vec3 { x:float; y:float; z:float; }) can
be mapped to a "mathfu::vec3" native type in NativeTables.  This requires
users to provide Pack and UnPack functions that convert between the
Table and native types.  This is done by adding the "native_type" attribute
to the table definition.

To support user-defined flatbuffers::Pack and flatbuffers::UnPack functions,
support a "native_include" markup that will generate a corresponding

Also add an UnPackTo function which allows users to pass in a pointer to
a NativeTable object into which to UnPack the Table.  The existing UnPack
function is now simply:

  NativeTable* UnPack() {
    NativeTable* obj = new NativeTable();
    Table::UnPackTo(obj);
    return obj;
  }

Finally, allow native types to be given a default value as well which are
set in the NativeTable constructor.  This is done by providing a
"native_default" attribute to the member of a table.

Change-Id: Ic45cb48b0e6d7cfa5734b24819e54aa96d847cfd
2017-01-18 16:23:35 -08:00
Wouter van Oortmerssen 42a265b419 Add no-op for padding variables to prevent clang compiler warning.
Change-Id: I119ee7109bfa2b0be0f468d2b2be459f45d1bb11
2017-01-18 16:17:08 -08:00
Wouter van Oortmerssen 4bc4979acc Fix compiler warning on Visual Studio.
Change-Id: Ifda5f2c32c6484508d5e12a463d6373798f1f523
2017-01-18 16:09:35 -08:00
Wouter van Oortmerssen b095367d17 Merge branch 'master' of https://github.com/google/flatbuffers 2017-01-18 14:58:09 -08:00
Wouter van Oortmerssen eac2905568 Fixed unions not being parsed correctly in JSON.
This would happen if they were supplied in an order that does not match
the schema relative to other fields. It now supports any ordering.

Change-Id: I9d309cd4e6e5c470f01d9d431806eba4f9f46559
Tested: on Linux.
2017-01-18 14:54:16 -08:00
Georges Savoundararadj 12fd0c6838 GenEnum: bit_flags: Remove useless conditions (#4141)
The conditions to add the "NONE" or "ANY" value in the enum were useless
because the user cannot provide a zero value or a bitmask (for "ANY") in
the bit_flags enum type.
2017-01-18 09:59:13 -08:00
Wouter van Oortmerssen 19101826a8 Fix unused field warning in clang.
Change-Id: I71d590a1e5b2709f0e2dcf97faaebda5cb918fc7
Tested: on Linux.
2017-01-13 18:30:57 -08:00
Wouter van Oortmerssen 7b94eab2b1 Add CodeWriter utility class.
Helps simplify code generation code.  Instead of this:
  code += "inline const " + cpp_qualified_name + " *Get";
  code += name;
  code += "(const void *buf) {\n  return flatbuffers::GetRoot<";
  code += cpp_qualified_name + ">(buf);\n}\n\n";

You do this:
  code.SetValue("NAME", struct_def.name);
  code.SetValue("CPP_NAME", cpp_qualified_name);
  code += "inline const {{CPP_NAME}} *Get{{NAME}}(const void *buf) {";
  code += "  return flatbuffers::GetRoot<{{CPP_NAME}}>(buf);";
  code += "}";
  code += "";

Updated the CPP code generator to use the CodeWriter class.  Most of the
changes in the generated code are white-space changes, esp. around new
lines (since the code generator class automatically appends new lines
when appending a string).  Actual code changes include:

* Renamed "rehasher" to "_rehasher" for consistency with other args in
  Pack function.

* Renamed "union_obj" to "obj: in UnPack function.

* Always do "(void)_o;" to prevent unused variable warning in Create
  function (instead of only doing it if there are no fields) in order
  to avoid two-passes.

* Renamed padding variables from __paddingX to paddingX__.
  "Each name that contains a double underscore (_ _) [...] is reserved
   to the implementation for any use."  C++ standards 17.4.3.1.2.

* Add braces around switch cases.

* Calculate index as a separate statement in EnumName function, eg.
    const size_t index = ...;
    return EnumNamesX()[index];
  vs.
    return EnumNamesX()[...];

* Stored end table offset in variable in Finish() functions, eg.
    const auto end = fbb_.EndTable(start_, ...);
    auto o = flatbuffers::Offset<T>(end);
  vs.
    auto o = flatbuffers::Offset<T>(fbb_.EndTable(start, ...));

* Separate reinterpret_cast calls from function calls in Union
  functions, eg.
    auto ptr = reinterpret_cast<const T *>(obj);
    return ptr->UnPack(resolver);
  vs.
    return reinterpret_cast<const T *>(obj)->UnPack(resolver);

* Removed unecessary (void)(padding__X) no-ops from constructors, eg.
    Test(int16_t a, int8_t b) : ... {
      (void)__padding0;  // <-- Removed this line.
    }

In the idl_gen_cpp.cpp file itself, I refactored some code generation into
new functions: GenParam, GenNativeTable, GenVerifyCall, GenBuilders,
GenUnpackFieldStatement, and GenCreateParam.

Change-Id: I727b1bd8719d05b7ce33cbce00eb58fda817b25d
2017-01-13 17:44:42 -08:00
gbeili 1a21b54560 Add a builder option to enable/disable vtables deduplication. (#4132)
* Add a builder option to enable/disable vtables deduplication.

* address code review comments
2017-01-11 10:36:18 -08:00
Pascal S. de Kloe b55f18649a Resolve Go fmt and vet warnings (#4134)
* Resolve Go fmt and vet warnings.

* Undo generated code gofmt.
2017-01-09 17:13:44 -08:00
Wouter van Oortmerssen e2373668d9 Merge branch 'master' of https://github.com/google/flatbuffers 2017-01-09 15:55:18 -08:00
Wouter van Oortmerssen 8c1a723ba5 Fixed GRPC method name generation.
Change-Id: I827b7e9aee1edb77752322455f7b6fafac16fb1d
Tested: on Linux.
2017-01-09 15:54:31 -08:00
Mateusz Pusz ab7949dc16 Cold part of make_space() code moved to reallocate member function. (#4130)
Change makes make_space() code much friendlier for the compiler to inline which makes significant (measurable) performance improvements.
2017-01-09 10:10:11 -08:00
Wouter van Oortmerssen 2c4dce5ba7 Re-applied reverted fix, adding missing codegen files.
Change-Id: I301d29835fb0baffd859950eb0fb3056e4f4d66b
2017-01-04 10:41:31 -08:00
Wouter van Oortmerssen cc84240098 Misc idl_gen_cpp cleanup
- Update to be const-correct where possible.
- Consistently pass |code| as pointer instead of non-const-ref.
- No newlines (\n) characters in the middle of code strings.
- Use if-else if-else statements instead of nested ternary operators.
- Ensure all lines end at 80 chars.
- Make utility functions static.

From cl/143505731.

Change-Id: If0fab9ee75de5af963367a948dddf53af93f73b4
2017-01-04 10:12:39 -08:00
Wouter van Oortmerssen b29ba4c70c Updated version to 1.5
Change-Id: I34007829cdd3ad024df21f68bb369016d5d21131
2017-01-03 14:56:44 -08:00
Yonggang Li fea6b525ee fix memory leak (#4126) 2017-01-03 13:54:15 -08:00
CarsarSky 69dc71b5ed Fix C++ gRPC test with streaming method (#4123) 2016-12-28 11:50:41 -08:00
Wouter van Oortmerssen 1a89682251 Merge branch 'master' of https://github.com/google/flatbuffers 2016-12-21 18:06:10 -08:00
Wouter van Oortmerssen 5fd0fefab6 Fixed empty structs generating illegal constructor in C++.
Change-Id: I60418d597b497c3cfa655ad76b3128351e9139f2
2016-12-21 18:04:31 -08:00
Ankur Dave f8a964d2b0 Fix call to Verifier::VerifyBuffer from BufferRef (#4124)
3a1f776132 added a required identifier parameter
to Verifier::VerifyBuffer but did not update the templated call site in
BufferRef. This causes errors like the following when trying to instantiate the
call site by calling BufferRef::Verify():

    include/flatbuffers/flatbuffers.h: In instantiation of ‘bool flatbuffers::BufferRef<T>::Verify() [with T = MyType]’:
    MyApp.cpp:16:3:   required from here
    include/flatbuffers/flatbuffers.h:1421:37: error: no matching function for call to ‘flatbuffers::Verifier::VerifyBuffer()’
         return verifier.VerifyBuffer<T>();
                                         ^
    include/flatbuffers/flatbuffers.h:1421:37: note: candidate is:
    include/flatbuffers/flatbuffers.h:1352:29: note: template<class T> bool flatbuffers::Verifier::VerifyBuffer(const char*)
       template<typename T> bool VerifyBuffer(const char *identifier) {
                                 ^
    include/flatbuffers/flatbuffers.h:1352:29: note:   template argument deduction/substitution failed:
    include/flatbuffers/flatbuffers.h:1421:37: note:   candidate expects 1 argument, 0 provided
         return verifier.VerifyBuffer<T>();
                                         ^

This commit fixes the BufferRef call site by adding a nullptr argument.
2016-12-21 17:49:45 -08:00
Zarian Waheed 84033ae035 Added helper methods to access struct through reflection. (#4120)
* Added helper methods to access struct through reflection. Also added unit test for it.

* Added a TODO comment to check for the is_struct flag.
2016-12-21 17:48:21 -08:00
Wouter van Oortmerssen b9efbf6a3d Fixed more Windows build errors.
Change-Id: I556e1c103e8501dc144b16c8698463253de6f4fb
2016-12-21 17:45:27 -08:00
Wouter van Oortmerssen 13194ececa Fixed Windows compiler warning.
Change-Id: I12b31227d4545a8897f638754d6a9ccd029f177e
2016-12-21 16:16:52 -08:00
wvo 9ec9303abb Go related style fixes.
Change-Id: Ie854ace69a21ef685e1ade5584f9d9ce4e8b41f1
2016-12-21 14:32:44 -08:00
Wouter van Oortmerssen 03ee3db240 Fixed Windows build errors.
Change-Id: I11548bfa3cfe307598eb59c56412974c349d614d
2016-12-19 17:04:35 -08:00
Wouter van Oortmerssen cf825b8819 Added missing generated code from previous commits.
Change-Id: Id7053e4cb5a085a4b047c86ff1f2269329ff7f54
2016-12-19 16:28:06 -08:00
Wouter van Oortmerssen 377a8ba6b2 Merge branch 'master' of https://github.com/google/flatbuffers 2016-12-19 16:26:57 -08:00
Wouter van Oortmerssen 13cf6e66e3 Merge "Documentation improvements: style guide & guide lines." into ub-games-master 2016-12-20 00:25:31 +00:00
Wouter van Oortmerssen 81b6bacead Documentation improvements: style guide & guide lines.
Bug: 22346508
Change-Id: I3f6e6b2811adaaf9d79faca8cdd00af3927299b5
2016-12-19 16:04:08 -08:00
Wouter van Oortmerssen e6fa14a08d Add default values (if they exist) to native tables.
From cl/142307012.

Change-Id: I54d550573f6506b92ad18e7cc90bcd8589259e52
2016-12-19 15:43:03 -08:00
Wouter van Oortmerssen c66683f27f Add ::Set function to Unions to make memory ownership clear.
Unions own the NativeTable* value member because they need to destroy them
when the Union goes out of scope.  Currently, the data is destroyed by calling
delete, which means that the member needs to be allocated with new.  However,
making the allocation the responsibility of the client and the destruction
the responsibility of the Union can lead to potential errors.  Adding a
Set function will ensure that the memory is allocated correctly so that it
can be deleted later.

From cl/142161569.

Change-Id: I4605f26d2749164819bfae0140e5fae08442b50a
2016-12-19 15:21:08 -08:00
Zarian Waheed 6d6271db2f Changes for verifying a buffer dynamically using reflection. (#4102)
* Changes for verifying a buffer dynamically using reflection.

* Fixing build issues on linux and applied code reformatting.

* Fixing the file order in cmake file that was messing up the macro based code inclusion.

Added tests for reflection based verification.

* Changes for verifying a buffer dynamically using reflection.

Fixing build issues on linux and applied code reformatting.

Fixing the file order in cmake file that was messing up the macro based code inclusion.

Added tests for reflection based verification.

* Incorporated the code review changes that were requested:

1. Changed the Verify function signature.
2. Changed the variable names to use snake_case.
3. Added better comments.
4. Refactored duplicate code.
5. Changed the verifier class so that it has the same size when compiled with or without FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE macro.

* Setting FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE and FLATBUFFERS_DEBUG_VERIFICATION_FAILURE through cmake for flattests so that it gets propagted to all translation units of flattests.

* Making the Verifier struct fields the same in all cases. Also reverting the target_compile_definitions change in cmake file because build machine on travis does not have cmake version 3.0 or higher which was the version when target_compile_definitions was added in cmake.

* Defining macros through cmake in a portable way using functions that are available in cmake 2.8.
2016-12-16 08:46:30 -08:00
krupnov ab76c57ec8 random access iterator for vector added (#4119)
* random access iterator for vector added

* Style changes
2016-12-16 08:37:04 -08:00
Wouter van Oortmerssen d1e8899310 Fixed JS outputting helper for Int64Array.
Change-Id: I7d23fa3416feb78ea18d2c451e7b4e1d9be11bfc
2016-12-14 10:35:26 -08:00
Wouter van Oortmerssen ccba2edb7c Made GRPC generator missing into a warning.
Change-Id: Iceb1f5b78cff6227905b8a23eb70e9ef6ce909ed
2016-12-14 10:32:44 -08:00
Wouter van Oortmerssen 2a7a44be33 Improving AppVeyor CI with other languages.
Change-Id: Iff630905b5f90814c5f728e3c0e10f7fcd67c7fe
2016-12-12 18:02:13 -08:00
Ricardo Quesada 6301da75d1 add weapon + equipment to json example (#4114)
update json with documentation

removed comments
2016-12-12 14:12:56 -08:00
Robert 059661b9ac Merge pull request #4112 from manolama/tweaks
Restore the ''import "unsafe'' removed in 36daedf35fd0cc2ad0e5e24d187…
2016-12-09 14:29:57 -08:00
Manolama dc5975ba7a Restore the ''import "unsafe'' removed in 36daedf35f.
This was causing build failures with tools dependent on Flatbuffers in Go.
E.g.
go/src/github.com/google/flatbuffers/go/sizes.go:50: undefined: unsafe in unsafe.Pointer
2016-12-08 22:19:33 -08:00
Robert 0de4f3f75b Create basic issue template (#4107)
* Create basic issue template

* Update ISSUE_TEMPLATE.md
2016-12-07 14:17:30 -08:00
Robert b59aafc659 Merge pull request #3791 from mmastrac/master
Avoid unsafe when sizing types
2016-12-07 11:51:11 -08:00
Robert 92a6ae93fa Merge pull request #3977 from gonzaloserrano/feature/go-generic-deserialitzation
Add a generic way to deserialize a flatbuffer in Go.
2016-12-07 11:17:55 -08:00
Ronak Jain a31ddd2bb3 Support for Golang GRPC (Experimental) (#4082)
* support for grpc golang

* refactored grpc go generator

* added grpc-go test and refactored

* refactored idl_gen_grpc.cpp

* fixed grpc generate method name

* refactored flatc and fixed line length issue

* added codec to go lib and fixed formatting issues

* fixed spacing issues
2016-12-05 13:20:38 -08:00
Wouter van Oortmerssen bc2ec7119b Adds typedefs and functions to help write generic code.
The following changes have been made to the C++ codegen to enable writing generic code
that uses the Table and NativeTable types.

- Adds TableType and NativeTableType typedefs to NativeTable and Table structs.
- Adds GetFullyQualifiedName() to NativeTables if --gen-name-strings is set.
- Adds a static Pack function to Tables that simply calls the global CreateX functions.

See cr/140391505 as an example of improved usage.

From cl/140529288.

Change-Id: Idec137c16129e15c1783f94fabdcea24aeeaaef6
2016-12-02 14:25:39 -08:00
Wouter van Oortmerssen 641b397f8b Allows structs to be stored directly as member variables.
Introduce a "native_inline" attribute that can be applied on fields that are structs.
This results in NativeTable code generation that sets the struct "inline" rather than
storing it in a pointer.

From cl/140527470.

Change-Id: I208724f552b8b921b20923e0bf82f42cb3582416
2016-12-02 14:25:08 -08:00