James Kuszmaul | f5eb468 | 2023-09-22 17:16:59 -0700 | [diff] [blame^] | 1 | #ifndef AOS_FLATBUFFERS_STATIC_FLATBUFFERS_H_ |
| 2 | #define AOS_FLATBUFFERS_STATIC_FLATBUFFERS_H_ |
| 3 | #include <map> |
| 4 | #include <set> |
| 5 | #include <string> |
| 6 | #include <string_view> |
| 7 | #include <vector> |
| 8 | |
| 9 | #include "flatbuffers/reflection_generated.h" |
| 10 | namespace aos::fbs { |
| 11 | |
| 12 | // Raw C++ code needed to represent a single flatbuffer table. |
| 13 | // The various strings in this struct represent the actual C++ code that will be |
| 14 | // used for this object; it is split up into pieces in order to allow us to |
| 15 | // combine multiple flatbuffer tables into a single generated file (namely, |
| 16 | // pulling the include declarations out to the top and including a set of |
| 17 | // dependencies so that we can order the code correctly). |
| 18 | // Primarily exposed here to allow for testing of intermediate functions. |
| 19 | struct GeneratedObject { |
| 20 | // Fully qualified name of the object, in flatbuffer schema rules (e.g. |
| 21 | // aos.examples.Ping). |
| 22 | std::string name; |
| 23 | // All #include statements required for this object. |
| 24 | std::set<std::string> include_declarations; |
| 25 | // Fully qualified names of all sub-objects, in flatbuffer schema rules (e.g. |
| 26 | // aos.examples.Ping). Used to manage ordering of codegen. |
| 27 | std::set<std::string> subobjects; |
| 28 | // Actual code specific to this object. |
| 29 | std::string code; |
| 30 | }; |
| 31 | |
| 32 | // Produces generated code for all flatbuffer tables in the file corresponding |
| 33 | // to the provided Schema object. |
| 34 | std::string GenerateCodeForRootTableFile(const reflection::Schema *schema); |
| 35 | |
| 36 | // Helper functions to generate the code for individual objects; primarily |
| 37 | // exposed for testing. |
| 38 | GeneratedObject GenerateCodeForObject(const reflection::Schema *schema, |
| 39 | int object_index); |
| 40 | GeneratedObject GenerateCodeForObject(const reflection::Schema *schema, |
| 41 | const reflection::Object *object); |
| 42 | } // namespace aos::fbs |
| 43 | #endif // AOS_FLATBUFFERS_STATIC_FLATBUFFERS_H_ |