summaryrefslogtreecommitdiff
path: root/src/idl_gen_fbs.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-01-25Refactor FieldDef to model presense as an enum rather than 2 bools. (#6420)Casper1-1/+1
* 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>
2020-03-02Added --filename-suffix and --filename-ext to flatc (#5778)Derek Bailey1-2/+6
* 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-01-06(Optionally) add an additional suffix namespace to generated fbs files. (#5698)Michael Beardsworth1-0/+7
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.
2019-12-30Correct inverted logic around include prefixes. (#5689)Michael Beardsworth1-2/+2
4d1a9f8d9eab9fc6762e03cd862576965a0c6920 inverted the logic around keeping the include prefix. This change fixes the error.
2019-12-23Improve import handling for proto conversion (#5673)Michael Beardsworth1-4/+9
* 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-05-02Fix issues with uint64 enums (#5265)Vladimir Glavnyy1-1/+1
* 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-04-08Part of #5265, neutral changes (#5281)Vladimir Glavnyy1-2/+1
2018-03-05Protobufs: Added '--oneof-union' option. (#4647)Nik Hemmings1-2/+8
* Added '--oneof-union' option. Used with the .proto -> .fbs converter, will translate protobuff oneofs to flatbuffer unions. Updated proto test to check both methods of converting oneofs. * Added '--oneof-union' option. Used with the .proto -> .fbs converter, will translate protobuff oneofs to flatbuffer unions. Updated proto test to check both methods of converting oneofs. * FlatBuffers: Moved MakeCamel() into idl_parser.cpp Removes library dependency on Java/C# generator code.
2017-12-21Made all C++ files clang-formatted.Wouter van Oortmerssen1-20/+19
Also added missing generated files. Change-Id: Ifd22a643a08e3f2edfce92812ed57b87fc0e1875
2017-10-06Improved .proto conversion.Wouter van Oortmerssen1-19/+22
- Allowed enums to be declared before use. - Generalized parsing of `required`. - Reworked escaping of namespaces. - Escaping field names that are C++ keywords. - Many smaller fixes. Change-Id: Ie580de7b70dc208f676f4f71bb0d061808648b8d Tested: on Linux.
2017-06-02Track included files in PATH-agnostic way. (#4329)Pavel Kalinnikov1-5/+5
* Track included files in PATH-agnostic way. Use full paths as keys in the map of included files. Store logical include path as a value, in order to put it to the generated file. * Fix tests by accepting null |include_filename|. * Fix self-includes code generators.
2017-01-13Add CodeWriter utility class.Wouter van Oortmerssen1-0/+1
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
2016-07-09Update idl_gen_fbs.cppRaman1-1/+1
2016-07-09Update idl_gen_fbs.cppRaman1-13/+12
2016-07-05Update idl_gen_fbs.cppRaman1-1/+1
2016-07-05Update idl_gen_fbs.cppRaman1-9/+8
2016-07-04Update idl_gen_fbs.cppRaman1-11/+15
2015-12-04Added --gen-all to generate code for a schema and all its includes.Wouter van Oortmerssen1-6/+4
Also refactored the way options are stored. Change-Id: I709ac908cd2aba396c9c282725cf1d42ccce0882 Tested: on Linux.
2015-10-13Added support for imports and many other .proto features.Wouter van Oortmerssen1-12/+38
Change-Id: I6600021b7ec8c486794349511232c3e604421c5b Tested: on Linux.
2015-04-01Generate appropriate schema doc comments from .proto filesAdvay Mengle1-0/+4
- Add parse handling of .proto struct and field doc comments (enums and their values were already handled) - Add FBS generation handling of doc comments for structs, their fields, enums, and their values (requires linking idl_gen_general in the test binary build) - Tested using test.proto|golden with doc comments added. Xcode run of flattest passes. Change-Id: Idff64dd8064afba227174ab77d2c7be22d006628
2015-03-11Fix for VS 2015 stricter warnings about "shadowed" names.Max Galkin1-6/+6
This change renames a few variables to fix the build in VS 2015. VS 2015 new warnings: http://blogs.msdn.com/b/vcblog/archive/2014/11/12/improvements-to-warnings-in-the-c-compiler.aspx Change-Id: Ic9c3f75ee717f0125960c813df442ed4fbcceb4a
2014-10-15Added .proto parsing and convertion to .fbs.Wouter van Oortmerssen1-0/+100
Bug: 15777858 Change-Id: Iabef9b8c8044e593bb89510feebdee00d2f1840b Tested: on Linux and Windows.