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