blob: 6a5f800abfe0f0415ca47ffdb5b8e9229e51707b [file] [log] [blame]
James Kuszmaulf5eb4682023-09-22 17:16:59 -07001#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"
10namespace 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.
19struct 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.
James Kuszmaul9a2d5f02023-12-14 11:38:35 -080034// file_hint is the name of the file that we should be generating code for; this
35// is used if there is no root table specified for the fbs file so that we can
36// infer which objects to generate code for.
37std::string GenerateCodeForRootTableFile(const reflection::Schema *schema,
38 std::string_view file_hint);
James Kuszmaulf5eb4682023-09-22 17:16:59 -070039
40// Helper functions to generate the code for individual objects; primarily
41// exposed for testing.
42GeneratedObject GenerateCodeForObject(const reflection::Schema *schema,
43 int object_index);
44GeneratedObject GenerateCodeForObject(const reflection::Schema *schema,
45 const reflection::Object *object);
46} // namespace aos::fbs
47#endif // AOS_FLATBUFFERS_STATIC_FLATBUFFERS_H_