blob: 11e21aeec71b9df3dae2676cc76499f4c0ba209e [file] [log] [blame]
James Kuszmaulf5eb4682023-09-22 17:16:59 -07001#ifndef AOS_FLATBUFFERS_STATIC_FLATBUFFERS_H_
2#define AOS_FLATBUFFERS_STATIC_FLATBUFFERS_H_
Stephan Pleines6191f1d2024-05-30 20:44:45 -07003#include <set> // IWYU pragma: keep
James Kuszmaulf5eb4682023-09-22 17:16:59 -07004#include <string>
5#include <string_view>
James Kuszmaulf5eb4682023-09-22 17:16:59 -07006
Stephan Pleines6191f1d2024-05-30 20:44:45 -07007#include "flatbuffers/reflection_generated.h" // IWYU pragma: keep
8
James Kuszmaulf5eb4682023-09-22 17:16:59 -07009namespace 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.
18struct 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 Kuszmaul9a2d5f02023-12-14 11:38:35 -080033// 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.
36std::string GenerateCodeForRootTableFile(const reflection::Schema *schema,
37 std::string_view file_hint);
James Kuszmaulf5eb4682023-09-22 17:16:59 -070038
39// Helper functions to generate the code for individual objects; primarily
40// exposed for testing.
41GeneratedObject GenerateCodeForObject(const reflection::Schema *schema,
42 int object_index);
43GeneratedObject GenerateCodeForObject(const reflection::Schema *schema,
44 const reflection::Object *object);
45} // namespace aos::fbs
46#endif // AOS_FLATBUFFERS_STATIC_FLATBUFFERS_H_