]> git.tdb.fi Git - libs/game.git/blob - tools/setupgen/setupgen.h
e4c1b333b2df110130c7ec203d58c3fcbba0839f
[libs/game.git] / tools / setupgen / setupgen.h
1 #ifndef SETUPGEN_H_
2 #define SETUPGEN_H_
3
4 #include <list>
5 #include <map>
6 #include <memory>
7 #include <set>
8 #include <string>
9 #include <msp/core/application.h>
10 #include <msp/datafile/objectloader.h>
11 #include <msp/fs/path.h>
12 #include "enum.h"
13 #include "struct.h"
14 #include "type.h"
15
16 class SetupGen: public Msp::RegisteredApplication<SetupGen>
17 {
18 private:
19         struct Module
20         {
21                 std::string name_space;
22                 std::vector<std::unique_ptr<Enum>> enums;
23                 std::vector<std::unique_ptr<Struct>> structs;
24         };
25
26         class Loader: public Msp::DataFile::ObjectLoader<SetupGen>
27         {
28         private:
29                 Module &mod;
30
31         public:
32                 Loader(SetupGen &, Module &);
33
34         private:
35                 void init_actions() override;
36
37                 void enum_def(const Msp::DataFile::Symbol &);
38                 void name_space(const std::string &);
39                 void struct_def(Struct::Kind, const Msp::DataFile::Symbol &);
40         };
41
42         std::string in_fn;
43         std::string out_fn;
44         std::list<Module> modules;
45         std::map<std::string, Type> types;
46         std::vector<std::unique_ptr<Enum>> enums;
47         std::vector<std::unique_ptr<Struct>> structs;
48         std::set<std::string> headers;
49
50 public:
51         SetupGen(int, char **);
52
53         int main() override;
54 private:
55         void create_standard_types();
56         Type &add_type(const std::string &, Type::Kind);
57 public:
58         const Type &get_type(const std::string &) const;
59
60 private:
61         void load(const Msp::FS::Path &);
62         void collect_headers(const Module &);
63         void generate_header(const Module &, Msp::IO::Base &) const;
64         void generate_code(const Module &, Msp::IO::Base &) const;
65 };
66
67 #endif