X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=tools%2Fsetupgen%2Fsetupgen.cpp;h=efb93fb81c32e80f0093a5fbd92396996ea0678a;hb=c7174843c35e0f1f8f2d6e2d4cdbb386f2a82361;hp=083fc8a96be3e6ec158d18e10de7ca993b2f0bb0;hpb=f4ca190e869b9d03bf4f8b7b002c65af9f56c0ad;p=libs%2Fgame.git diff --git a/tools/setupgen/setupgen.cpp b/tools/setupgen/setupgen.cpp index 083fc8a..efb93fb 100644 --- a/tools/setupgen/setupgen.cpp +++ b/tools/setupgen/setupgen.cpp @@ -1,6 +1,8 @@ #include "setupgen.h" +#include #include #include +#include #include #include #include @@ -11,10 +13,15 @@ using namespace Msp; SetupGen::SetupGen(int argc, char **argv) { + vector import_dirs; + GetOpt getopt; + getopt.add_option('I', "importdir", import_dirs, GetOpt::REQUIRED_ARG); getopt.add_option('o', "output", out_fn, GetOpt::REQUIRED_ARG); getopt.add_argument("input_file", in_fn, GetOpt::REQUIRED_ARG); getopt(argc, argv); + + import_path.insert(import_path.end(), import_dirs.begin(), import_dirs.end()); } int SetupGen::main() @@ -192,6 +199,7 @@ void SetupGen::Loader::init_actions() add("component", &Loader::struct_def, Struct::COMPONENT); add("entity", &Loader::struct_def, Struct::ENTITY); add("enum", &Loader::enum_def); + add("import", &Loader::import); add("namespace", &Loader::name_space); } @@ -200,9 +208,24 @@ void SetupGen::Loader::enum_def(const DataFile::Symbol &n) Enum en(n.name); load_sub(en); Type &type = obj.add_type(n.name, Type::ENUM); + type.set_cpp_type(join(mod.name_space, "::", type.get_cpp_type())); type.set_enum(*mod.enums.emplace_back(make_unique(move(en)))); } +void SetupGen::Loader::import(const string &n) +{ + string fn = n+".mgs"; + FS::Path full_path; + if(!ranges::any_of(obj.import_path, [&full_path, &fn](const FS::Path &p){ + full_path = p/fn; + return FS::exists(full_path); + })) + throw IO::file_not_found(fn); + + obj.load(full_path); + obj.headers.insert(n+".h"); +} + void SetupGen::Loader::name_space(const string &ns) { mod.name_space = ns; @@ -213,5 +236,6 @@ void SetupGen::Loader::struct_def(Struct::Kind kind, const DataFile::Symbol &n) Struct sct(n.name+"Setup", kind); load_sub(sct, obj); Type &type = obj.add_type(n.name, Type::STRUCT); + type.set_cpp_type(join(mod.name_space, "::", type.get_cpp_type())); type.set_struct(*mod.structs.emplace_back(make_unique(move(sct)))); }