From 420ab33324d30aef7d76fc7de8c1c28d94671d7a Mon Sep 17 00:00:00 2001 From: svec1 Date: Thu, 23 Jan 2025 15:44:10 +0000 Subject: [PATCH 01/38] Last build before major rebuild --- src/bs/bw_defs.hpp | 6 +- src/bs/bwbuild_sys.cpp | 105 ++++-------------- src/bs/bwbuild_sys.hpp | 15 +-- src/bs/bwcache_api.hpp | 11 ++ src/bs/bwcache_lua.cpp | 12 +- src/bs/bwgenerator_api.hpp | 4 +- src/bs/bwgenerator_integral.cpp | 2 + src/bs/bwgenerator_integral.hpp | 9 +- src/bs/bwgenerator_lua.cpp | 40 ++++--- src/bs/bwgntools.cpp | 79 ++++++++++++- src/bs/bwgntools.hpp | 7 ++ src/bs/bwluatoolslang.hpp | 4 +- src/bs/lang/static_linking_func.cpp | 2 +- src/bweas.cpp | 2 +- src/kernel/high_level/assistant.cpp | 2 + .../hook_linux_lib/decl_func_fbwhook.c | 4 +- 16 files changed, 170 insertions(+), 134 deletions(-) diff --git a/src/bs/bw_defs.hpp b/src/bs/bw_defs.hpp index a5d94a0..48c4fdb 100644 --- a/src/bs/bw_defs.hpp +++ b/src/bs/bw_defs.hpp @@ -15,13 +15,17 @@ #define BWEAS_VERSION_MINOR "1" #define BWEAS_VERSION_PATCH "0" +#define BWEAS_INFO "bweas version " BWEAS_VERSION_STR "\nrep on github - https://github.com/svec1/bweas" + #define BWEAS_HELP \ "bweas-call: \n bweas ... path_depending\n bweas path_bweas_config ..." \ "\nAcceptable parameters:" \ "\n --build - builds the project (either by executing the configuration file or deserializing the cache file " \ "if it exists)" \ "\n --cfg - executes the configuration file if it has been changed and creates a new cache file" \ - "\n --package - creates a bweas package based on the transferred json file(json config)" + "\n --package - creates a bweas package based on the transferred json file(json config)" \ + "\n --help - outputs the syntax of the bweas call as well as its possible functions" \ + "\n --version - outputs the version of bweas" namespace bweas { using bwarg = std::pair; diff --git a/src/bs/bwbuild_sys.cpp b/src/bs/bwbuild_sys.cpp index a5584bf..04a1a26 100644 --- a/src/bs/bwbuild_sys.cpp +++ b/src/bs/bwbuild_sys.cpp @@ -4,6 +4,7 @@ #include "lang/static_struct.hpp" #include +#include #include #include #include @@ -42,7 +43,7 @@ bwbuilder::bwbuilder(int argv, char **args) { handle_args(vec_args); - if (mode_bweas != mode_working::build_package) { + if (mode_bweas != mode_working::build_package && mode_bweas != mode_working::undef) { assist << "Initializing system build - bweas " + bwbuilde_ver.get_str_version(); init(); } @@ -73,12 +74,7 @@ void bwbuilder::handle_args(std::vector args) { expected_path_bweas_config = 0; args[i].erase(args[i].find("--"), 2); if (args[i] == "build") { - if (!path_bweas_to_build.empty()) { - assist.next_output_important(); - assist << " - [BWEAS]: The build folder has already been set"; - continue; - } - else if (mode_bweas == mode_working::build_package) + if (mode_bweas == mode_working::build_package) throw bwbuilder_excp(args[i], "001", "-HAX"); if (mode_bweas == mode_working::collect_cfg) @@ -100,6 +96,10 @@ void bwbuilder::handle_args(std::vector args) { mode_bweas = mode_working::build_package; expected_path_json_cfg_package = 1; } + else if (args[i] == "help") + assist << BWEAS_HELP; + else if (args[i] == "version") + assist << BWEAS_INFO; else throw bwbuilder_excp("Parameter: " + args[i] + "\n" + BWEAS_HELP, "000", "-HAX"); } @@ -107,6 +107,8 @@ void bwbuilder::handle_args(std::vector args) { // --cfg or arg if (expected_path_bweas_config) { path_bweas_config = std::filesystem::absolute(args[i]).string(); + mode_bweas = mode_working::collect_cfg; + expected_path_bweas_config = 0; } // --build @@ -218,7 +220,7 @@ void bwbuilder::init() { generator_api::base_generator::createGeneratorLua(generator.src_lua_generator)); for (auto &package : loaded_packages) { - semantic_an::table_func tfuncs = module_mg.init_tsfunc(package.cfg_package.mds); + semantic_an::table_func tfuncs = module_manager.init_tsfunc(package.cfg_package.mds); for (const auto &func : tfuncs) module_tfuncs.insert(func); } @@ -343,29 +345,33 @@ void bwbuilder::build_targets() { out_targets[i].name_target + ": " + out_targets[i].name_generator, "002"); auto ¤t_generator = generators[out_targets[i].name_generator]; - current_generator->set_ccomponents(call_components); + current_generator->set_const_data(call_components, global_extern_args); current_generator->init(); if (out_targets[i].prj.vec_templates.size() == 0) throw bwbuilder_excp("There are no templates for the target - " + out_targets[i].name_target, "002"); - std::string dir_target = std::string(DIRWORK_ENV) + "/" + out_targets[i].name_target; + std::string dir_target = path_bweas_to_build + "/" + out_targets[i].name_target; if (!std::filesystem::is_directory(dir_target)) std::filesystem::create_directories(dir_target); - assist << "BUILDING A TARGET -" + out_targets[i].name_target; + assist << " - [BWEAS]: Build {" + out_targets[i].name_target + "}"; bwqueue_templates bw_tcmd; set_queue_templates(create_stack_target_templates(out_targets[i]), bw_tcmd); - parse_basic_args(out_targets[i], bw_tcmd); assist.switch_otp(0); auto cmd_s = current_generator->gen_commands( out_targets[i], bw_tcmd, dir_target, current_generator->input_files(out_targets[i], bw_tcmd, dir_target)); assist.switch_otp(1); + double k_state = 0.f; + for (const auto &cmd : cmd_s) { + k_state += 1.f / (double)cmd_s.size() * 100; + assist.next_output_important(); - assist << "Compile - " + cmd.first; + assist << "[" + std::to_string(k_state).erase(std::to_string((u32t)k_state).size() + 3, 4) + + "%]Compile - " + cmd.first; #if defined(WIN) if (system(cmd.second.c_str())) @@ -432,79 +438,6 @@ void bwbuilder::set_queue_templates(std::stack &&stack_target_templ } } -void bwbuilder::parse_basic_args(const var::struct_sb::target_out &target, bwqueue_templates &target_queue_templates) { - for (auto &trg_template : target_queue_templates) { - for (u32t i = 0; i < trg_template.args.size(); ++i) { - var::struct_sb::template_command::arg ¤t_arg = trg_template.args[i]; - if (current_arg.arg_t == var::struct_sb::template_command::arg::type::string || - current_arg.arg_t == var::struct_sb::template_command::arg::type::features || - current_arg.arg_t == var::struct_sb::template_command::arg::type::internal) - continue; - else if (current_arg.arg_t == var::struct_sb::template_command::arg::type::extglobal) { - const auto &extern_arg = - std::find_if(global_extern_args.begin(), global_extern_args.end(), - [current_arg](const std::pair extern_arg_tmp) { - return extern_arg_tmp.first == current_arg.str_arg; - }); - if (extern_arg == global_extern_args.end()) - throw bwbuilder_excp("[" + trg_template.name + - "] The specified external parameter does not exist - " + - current_arg.str_arg, - "002"); - - current_arg.str_arg = extern_arg->second; - } - else if (current_arg.arg_t == var::struct_sb::template_command::arg::type::trgfield) { - if (current_arg.str_arg == NAME_FIELD_TARGET_NAME) - current_arg.str_arg = target.name_target; - else if (current_arg.str_arg == NAME_FIELD_TARGET_LIBS) { - current_arg.str_arg = ""; - for (u32t k = 0; k < target.target_vec_libs.size(); ++k) { - current_arg.str_arg += target.target_vec_libs[k]; - if (k < target.target_vec_libs.size() - 1) - current_arg.str_arg += " "; - } - } - else if (current_arg.str_arg == NAME_FIELD_TARGET_TYPE) - current_arg.str_arg = var::struct_sb::target_t_str(target.target_t); - else if (current_arg.str_arg == NAME_FIELD_TARGET_CFG) - current_arg.str_arg = var::struct_sb::cfg_str(target.target_cfg); - else if (current_arg.str_arg == NAME_FIELD_TARGET_VER) - current_arg.str_arg = target.version_target.get_str_version(); - else if (current_arg.str_arg == NAME_FIELD_PROJECT_NAME) - current_arg.str_arg = target.prj.name_project; - else if (current_arg.str_arg == NAME_FIELD_PROJECT_VER) - current_arg.str_arg = target.prj.version_project.get_str_version(); - else if (current_arg.str_arg == NAME_FIELD_PROJECT_LANG) - current_arg.str_arg = var::struct_sb::lang_str(target.prj.lang); - else if (current_arg.str_arg == NAME_FIELD_PROJECT_PCOMPILER) - current_arg.str_arg = target.prj.path_compiler; - else if (current_arg.str_arg == NAME_FIELD_PROJECT_PLINKER) - current_arg.str_arg = target.prj.path_linker; - else if (current_arg.str_arg == NAME_FIELD_PROJECT_RFCOMPILER) - current_arg.str_arg = target.prj.rflags_compiler; - else if (current_arg.str_arg == NAME_FIELD_PROJECT_RFLINKER) - current_arg.str_arg = target.prj.rflags_linker; - else if (current_arg.str_arg == NAME_FIELD_PROJECT_DFCOMPILER) - current_arg.str_arg = target.prj.dflags_compiler; - else if (current_arg.str_arg == NAME_FIELD_PROJECT_DFLINKER) - current_arg.str_arg = target.prj.dflags_linker; - else if (current_arg.str_arg == NAME_FIELD_PROJECT_STD_C) - current_arg.str_arg = std::to_string(target.prj.standart_c); - else if (current_arg.str_arg == NAME_FIELD_PROJECT_STD_CPP) - current_arg.str_arg = std::to_string(target.prj.standart_cpp); - else if (current_arg.str_arg.find(NAME_FIELD_PROJECT_SRC_FILES) == 0) - continue; - else - throw bwbuilder_excp( - "[" + trg_template.name + "] There is no such parameter - " + current_arg.str_arg, "002"); - } - - current_arg.arg_t = var::struct_sb::template_command::arg::type::string; - } - } -} - void bwbuilder::imp_data_interpreter_for_bs() { const auto &global_templates = _bwlang.get_global_scope().get_vector_variables_t(); diff --git a/src/bs/bwbuild_sys.hpp b/src/bs/bwbuild_sys.hpp index dd5624e..63adf92 100644 --- a/src/bs/bwbuild_sys.hpp +++ b/src/bs/bwbuild_sys.hpp @@ -126,17 +126,11 @@ class bwbuilder final { void set_queue_templates(std::stack &&stack_target_templates, bwqueue_templates &target_queue_templates); - // Parses all the basic arguments for further template command generation - // Types of arguments that will be parsed: - // 1. extglobal - // 2. trgfield(except T_PROJECT_SRC_FILES) - void parse_basic_args(const var::struct_sb::target_out &target, bwqueue_templates &target_queue_templates); - private: cache_api::base_bwcache *_bwcache{NULL}; semantic_an::table_func module_tfuncs; - module::module_mg module_mg; + module::module_mg module_manager; std::vector loaded_packages; std::map generators; @@ -146,14 +140,15 @@ class bwbuilder final { std::vector call_components; bwargs global_extern_args; - static inline bool init_glob{0}; - std::string name_bweas_prg; - std::string path_bweas_config, path_bweas_to_build; + std::string path_bweas_config, path_bweas_to_build{DIRWORK_ENV}; + mode_working mode_bweas{mode_working::undef}; var::struct_sb::version bwbuilde_ver{BWEAS_VERSION_STR}; bool log{1}, output_log{1}; + + static inline bool init_glob{0}; }; } // namespace bweas diff --git a/src/bs/bwcache_api.hpp b/src/bs/bwcache_api.hpp index 85dd351..cd82b50 100644 --- a/src/bs/bwcache_api.hpp +++ b/src/bs/bwcache_api.hpp @@ -20,8 +20,10 @@ namespace bweas { namespace cache_api { +// Abstract class that bases API for creating cache generators class base_bwcache { public: + // A structure that is intermediate for transferring data to be hashed (and back). struct cache_data { cache_data() = default; @@ -37,11 +39,16 @@ class base_bwcache { base_bwcache() = default; public: + // A function that must be defined in a child class, and return a cache of data virtual std::string create_cache() = 0; + + // A function that must be defined in a child class and return cache data virtual const cache_data &get_cache_data(std::string cache_str) = 0; virtual void delete_cache() = 0; + // A number of factory functions to create all possible child classes that implement the bwcache cache generator + // based on the bwcache API public: static inline base_bwcache *create_fast_bwcache(); static inline base_bwcache *create_json_bwcache(); @@ -51,6 +58,7 @@ class base_bwcache { cache_data _cache_data; }; +// A basic cache generator that is fast but also creates a hard-to-read cache for humans to use class fast_bwcache final : private base_bwcache { public: fast_bwcache(); @@ -65,6 +73,8 @@ class fast_bwcache final : private base_bwcache { static inline bool init_glob_chfast{0}; }; +// The second basic cache generator, which in turn has a human readable form, +// but is also slow compared to fast_bwcache class json_bwcache final : private base_bwcache { public: json_bwcache(); @@ -79,6 +89,7 @@ class json_bwcache final : private base_bwcache { static inline bool init_glob_chjson{0}; }; +// A class providing an API for creating cache generators in lua, based on the bwcache API class lua_bwcache final : private base_bwcache { public: lua_bwcache() = delete; diff --git a/src/bs/bwcache_lua.cpp b/src/bs/bwcache_lua.cpp index 90a23f4..2b6d0f4 100644 --- a/src/bs/bwcache_lua.cpp +++ b/src/bs/bwcache_lua.cpp @@ -31,11 +31,11 @@ std::string lua_bwcache::create_cache() { std::vector> lccmp_s; for (const auto <arget_o : _cache_data.targets_o_p != nullptr ? *_cache_data.targets_o_p : _cache_data.targets_o) - ltargets_o.push_back(luatools_lang::conv_to_table(ltarget_o)); + ltargets_o.push_back(lua_tools::conv_to_table(ltarget_o)); for (const auto <cmd : _cache_data.templates) - ltcmd_s.push_back(luatools_lang::conv_to_table(ltcmd)); + ltcmd_s.push_back(lua_tools::conv_to_table(ltcmd)); for (const auto &lccmp : _cache_data.call_components) - lccmp_s.push_back(luatools_lang::conv_to_table(lccmp)); + lccmp_s.push_back(lua_tools::conv_to_table(lccmp)); try { return lua.call_function DEFINITION_FUNCTION_GENCACHE(NAME_FUNCTION_GENCACHE, ltargets_o, ltcmd_s, lccmp_s, @@ -68,11 +68,11 @@ const base_bwcache::cache_data &lua_bwcache::get_cache_data(std::string cache_st throw bwcache_excp(what.what(), "000"); } for (auto <arget_o : ltargets_o) - _cache_data.targets_o.push_back(luatools_lang::conv_to_target(ltarget_o)); + _cache_data.targets_o.push_back(lua_tools::conv_to_target(ltarget_o)); for (auto <cmd : ltcmd_s) - _cache_data.templates.push_back(luatools_lang::conv_to_template(ltcmd)); + _cache_data.templates.push_back(lua_tools::conv_to_template(ltcmd)); for (auto &lccmp : lccmp_s) - _cache_data.call_components.push_back(luatools_lang::conv_to_call_components(lccmp)); + _cache_data.call_components.push_back(lua_tools::conv_to_call_components(lccmp)); _cache_data.global_external_args = lglobal_external_args; diff --git a/src/bs/bwgenerator_api.hpp b/src/bs/bwgenerator_api.hpp index 18029c0..bf34219 100644 --- a/src/bs/bwgenerator_api.hpp +++ b/src/bs/bwgenerator_api.hpp @@ -56,10 +56,11 @@ class base_generator : public gninterface::interface_generator { ~base_generator() = default; public: - void set_ccomponents(std::vector &ccmp) { + void set_const_data(std::vector &ccmp, bwargs global_external_args) { ccmp_p = std::shared_ptr>( (std::vector *)&ccmp, [](const std::vector *) {}); + global_external_args_p = std::shared_ptr((bwargs *)&global_external_args, [](const bwargs *) {}); } public: @@ -75,6 +76,7 @@ class base_generator : public gninterface::interface_generator { protected: std::shared_ptr> ccmp_p; + std::shared_ptr global_external_args_p; }; // The class defines the API for internal generators, i.e. built into bweas as basic diff --git a/src/bs/bwgenerator_integral.cpp b/src/bs/bwgenerator_integral.cpp index f9b7ece..f17408c 100644 --- a/src/bs/bwgenerator_integral.cpp +++ b/src/bs/bwgenerator_integral.cpp @@ -10,6 +10,7 @@ using namespace bweas::bwexception; integral_generator::integral_generator(func_generator _generator_p, func_get_files_input _files_input_p) { if (!init_glob_gnint) { + assist.add_err("BWS-GNRT000", "Unable to parse basic arguments"); assist.add_err("BWS-GNRT001", "Internal global argument not found"); assist.add_err("BWS-GNRT002", "This generator does not have the specified features"); init_glob_gnint = 1; @@ -32,6 +33,7 @@ std::map> integral_generator::input_files( std::map integral_generator::gen_commands( const var::struct_sb::target_out &trg, bwqueue_templates &templates, std::string dir_work_endv, std::map> files_input) { + generator::tools::parse_basic_args(trg, templates, *global_external_args_p); return generator_p(trg, templates, *ccmp_p, files_input, dir_work_endv); } diff --git a/src/bs/bwgenerator_integral.hpp b/src/bs/bwgenerator_integral.hpp index 6627b4d..b536f1d 100644 --- a/src/bs/bwgenerator_integral.hpp +++ b/src/bs/bwgenerator_integral.hpp @@ -11,10 +11,11 @@ extern std::map> bwfile_inputs( const std::vector &ccmp_p, std::string dir_work_endv); // First and basic template-based command generator -extern std::map bwgenerator(const var::struct_sb::target_out &trg, bwqueue_templates &templates, - const std::vector &ccmp_p, - std::map> files_input, - std::string dir_work_endv); +extern std::map bwgenerator(const var::struct_sb::target_out &trg, + bwqueue_templates &templates, + const std::vector &ccmp_p, + std::map> files_input, + std::string dir_work_endv); } // namespace generator } // namespace bweas diff --git a/src/bs/bwgenerator_lua.cpp b/src/bs/bwgenerator_lua.cpp index c776694..1d58f6a 100644 --- a/src/bs/bwgenerator_lua.cpp +++ b/src/bs/bwgenerator_lua.cpp @@ -8,11 +8,12 @@ using namespace bweas::bwexception; lua_generator::lua_generator(std::string src_lua) { if (!init_glob_gnlua) { - assist.add_err("BWS-GNRT000", "Lua script not loaded"); - assist.add_err("BWS-GNRT001", "Failed to load lua script"); - assist.add_err("BWS-GNRT002", "No entry function for generator"); - assist.add_err("BWS-GNRT003", "Not found function for get input files"); - assist.add_err("BWS-GNRT004", "Run-time error"); + assist.add_err("BWS-GNRT000", "Unable to parse basic arguments"); + assist.add_err("BWS-GNRT001", "Lua script not loaded"); + assist.add_err("BWS-GNRT002", "Failed to load lua script"); + assist.add_err("BWS-GNRT003", "No entry function for generator"); + assist.add_err("BWS-GNRT004", "Not found function for get input files"); + assist.add_err("BWS-GNRT005", "Run-time error"); init_glob_gnlua = 1; } @@ -21,25 +22,25 @@ lua_generator::lua_generator(std::string src_lua) { lua.create(src_lua); } catch (std::exception &excp) { - throw bwgenerator_excp(excp.what(), "001"); + throw bwgenerator_excp(excp.what(), "002"); } } void lua_generator::init() { if (!lua.is_created()) - throw bwgenerator_excp("", "000"); + throw bwgenerator_excp("", "001"); else if (!lua.is_function(NAME_FUNCTION_GENLUA)) - throw bwgenerator_excp("", "002"); - else if (!lua.is_function(NAME_FUNCTION_FILECLUA)) throw bwgenerator_excp("", "003"); + else if (!lua.is_function(NAME_FUNCTION_FILECLUA)) + throw bwgenerator_excp("", "004"); bwlua::lua::array> ccmps; for (u32t i = 0; i < ccmp_p->size(); ++i) ccmps.emplace_back(bwlua::lua::array{(*ccmp_p)[i].name, (*ccmp_p)[i].name_program, (*ccmp_p)[i].pattern_ret_files}); - lua["get_name_output_file_lua"] << luatools_lang::get_name_output_file_lua; - lua["file_slc_mask"] << luatools_lang::file_slc_mask_lua; + lua["get_name_output_file_lua"] << lua_tools::get_name_output_file_lua; + lua["file_slc_mask"] << lua_tools::file_slc_mask_lua; lua["CCMPS"] = ccmps; } @@ -52,25 +53,28 @@ std::map> lua_generator::input_files( std::string dir_work_endv) { bwlua::lua::array> tcmd_s_vec; for (u32t i = 0; i < target_queue_templates.size(); ++i) - tcmd_s_vec.emplace_back(luatools_lang::conv_to_table(target_queue_templates[i])); + tcmd_s_vec.emplace_back(lua_tools::conv_to_table(target_queue_templates[i])); try { return bwlua::lua::to_map(lua.call_function DEFINITION_FUNCTION_FILECLUA( - NAME_FUNCTION_FILECLUA, luatools_lang::conv_to_table(target), tcmd_s_vec)); + NAME_FUNCTION_FILECLUA, lua_tools::conv_to_table(target), tcmd_s_vec)); } catch (std::exception &what) { - throw bwgenerator_excp(what.what(), "004"); + throw bwgenerator_excp(what.what(), "005"); } } std::map lua_generator::gen_commands( - const var::struct_sb::target_out &trg, bwqueue_templates &tcmd_s, std::string dir_work_endv, + const var::struct_sb::target_out &trg, bwqueue_templates &templates, std::string dir_work_endv, std::map> files_input) { + + generator::tools::parse_basic_args(trg, templates, *global_external_args_p); + std::vector> tcmd_s_vec; - for (u32t i = 0; i < tcmd_s.size(); ++i) - tcmd_s_vec.emplace_back(luatools_lang::conv_to_table(tcmd_s[i])); + for (u32t i = 0; i < templates.size(); ++i) + tcmd_s_vec.emplace_back(lua_tools::conv_to_table(templates[i])); - lua["CURRENT_TARGET"] = luatools_lang::conv_to_table(trg); + lua["CURRENT_TARGET"] = lua_tools::conv_to_table(trg); lua["CURRENT_QUEUE_TEMPLATES"] = tcmd_s_vec; lua["CURRENT_DIR"] = dir_work_endv; diff --git a/src/bs/bwgntools.cpp b/src/bs/bwgntools.cpp index 5eea8ad..cc879df 100644 --- a/src/bs/bwgntools.cpp +++ b/src/bs/bwgntools.cpp @@ -1,7 +1,8 @@ #include "bwgntools.hpp" -std::string bweas::generator::tools::get_name_output_file(std::string pattern_file, u32t index, - std::string dir_work_endv) { +using namespace bweas; + +std::string generator::tools::get_name_output_file(std::string pattern_file, u32t index, std::string dir_work_endv) { if (pattern_file.find(".") == pattern_file.npos) return dir_work_endv + "/" + pattern_file + std::to_string(index); std::string name_output_file_curr = pattern_file, extension_output_file_curr = pattern_file; @@ -10,4 +11,78 @@ std::string bweas::generator::tools::get_name_output_file(std::string pattern_fi if (index != 0) return dir_work_endv + "/" + name_output_file_curr + std::to_string(index) + extension_output_file_curr; return dir_work_endv + "/" + name_output_file_curr + extension_output_file_curr; +} + +void generator::tools::parse_basic_args(const var::struct_sb::target_out &target, + bwqueue_templates &target_queue_templates, const bwargs &global_extern_args) { + for (auto &trg_template : target_queue_templates) { + for (u32t i = 0; i < trg_template.args.size(); ++i) { + var::struct_sb::template_command::arg ¤t_arg = trg_template.args[i]; + if (current_arg.arg_t == var::struct_sb::template_command::arg::type::string || + current_arg.arg_t == var::struct_sb::template_command::arg::type::features || + current_arg.arg_t == var::struct_sb::template_command::arg::type::internal) + continue; + else if (current_arg.arg_t == var::struct_sb::template_command::arg::type::extglobal) { + const auto &extern_arg = + std::find_if(global_extern_args.begin(), global_extern_args.end(), + [current_arg](const std::pair extern_arg_tmp) { + return extern_arg_tmp.first == current_arg.str_arg; + }); + if (extern_arg == global_extern_args.end()) + throw bwexception::bwgenerator_excp("[" + trg_template.name + + "] The specified external parameter does not exist - " + + current_arg.str_arg, + "000"); + + current_arg.str_arg = extern_arg->second; + } + else if (current_arg.arg_t == var::struct_sb::template_command::arg::type::trgfield) { + if (current_arg.str_arg == NAME_FIELD_TARGET_NAME) + current_arg.str_arg = target.name_target; + else if (current_arg.str_arg == NAME_FIELD_TARGET_LIBS) { + current_arg.str_arg = ""; + for (u32t k = 0; k < target.target_vec_libs.size(); ++k) { + current_arg.str_arg += target.target_vec_libs[k]; + if (k < target.target_vec_libs.size() - 1) + current_arg.str_arg += " "; + } + } + else if (current_arg.str_arg == NAME_FIELD_TARGET_TYPE) + current_arg.str_arg = var::struct_sb::target_t_str(target.target_t); + else if (current_arg.str_arg == NAME_FIELD_TARGET_CFG) + current_arg.str_arg = var::struct_sb::cfg_str(target.target_cfg); + else if (current_arg.str_arg == NAME_FIELD_TARGET_VER) + current_arg.str_arg = target.version_target.get_str_version(); + else if (current_arg.str_arg == NAME_FIELD_PROJECT_NAME) + current_arg.str_arg = target.prj.name_project; + else if (current_arg.str_arg == NAME_FIELD_PROJECT_VER) + current_arg.str_arg = target.prj.version_project.get_str_version(); + else if (current_arg.str_arg == NAME_FIELD_PROJECT_LANG) + current_arg.str_arg = var::struct_sb::lang_str(target.prj.lang); + else if (current_arg.str_arg == NAME_FIELD_PROJECT_PCOMPILER) + current_arg.str_arg = target.prj.path_compiler; + else if (current_arg.str_arg == NAME_FIELD_PROJECT_PLINKER) + current_arg.str_arg = target.prj.path_linker; + else if (current_arg.str_arg == NAME_FIELD_PROJECT_RFCOMPILER) + current_arg.str_arg = target.prj.rflags_compiler; + else if (current_arg.str_arg == NAME_FIELD_PROJECT_RFLINKER) + current_arg.str_arg = target.prj.rflags_linker; + else if (current_arg.str_arg == NAME_FIELD_PROJECT_DFCOMPILER) + current_arg.str_arg = target.prj.dflags_compiler; + else if (current_arg.str_arg == NAME_FIELD_PROJECT_DFLINKER) + current_arg.str_arg = target.prj.dflags_linker; + else if (current_arg.str_arg == NAME_FIELD_PROJECT_STD_C) + current_arg.str_arg = std::to_string(target.prj.standart_c); + else if (current_arg.str_arg == NAME_FIELD_PROJECT_STD_CPP) + current_arg.str_arg = std::to_string(target.prj.standart_cpp); + else if (current_arg.str_arg.find(NAME_FIELD_PROJECT_SRC_FILES) == 0) + continue; + else + throw bwexception::bwgenerator_excp( + "[" + trg_template.name + "] There is no such parameter - " + current_arg.str_arg, "000"); + } + + current_arg.arg_t = var::struct_sb::template_command::arg::type::string; + } + } } \ No newline at end of file diff --git a/src/bs/bwgntools.hpp b/src/bs/bwgntools.hpp index 9d52eee..4fca1ea 100644 --- a/src/bs/bwgntools.hpp +++ b/src/bs/bwgntools.hpp @@ -13,6 +13,13 @@ namespace tools { // Generates a file name based on the pattern and the passed index of the given file extern std::string get_name_output_file(std::string pattern_file, u32t index, std::string dir_work_endv); +// Parses all the basic arguments for further template command generation +// Types of arguments that will be parsed: +// 1. extglobal +// 2. trgfield(except T_PROJECT_SRC_FILES) +extern void parse_basic_args(const var::struct_sb::target_out &target, bwqueue_templates &target_queue_templates, + const bwargs &global_extern_args); + } // namespace tools } // namespace generator diff --git a/src/bs/bwluatoolslang.hpp b/src/bs/bwluatoolslang.hpp index 5e620e9..0b27841 100644 --- a/src/bs/bwluatoolslang.hpp +++ b/src/bs/bwluatoolslang.hpp @@ -8,7 +8,7 @@ namespace bweas { -namespace luatools_lang { +namespace lua_tools { static inline bwlua::lua::table conv_to_table(const var::struct_sb::project &prj) { return bwlua::lua::table{ @@ -218,7 +218,7 @@ static inline int file_slc_mask_lua(lua_State *L) { return 1; } -} // namespace luatools_lang +} // namespace lua_tools } // namespace bweas diff --git a/src/bs/lang/static_linking_func.cpp b/src/bs/lang/static_linking_func.cpp index 3a128e5..0faca2a 100644 --- a/src/bs/lang/static_linking_func.cpp +++ b/src/bs/lang/static_linking_func.cpp @@ -19,7 +19,7 @@ static const std::array vec_name_config_var = { // ?????? static void update_cfg_struct(const std::string &name_var, var::scope &curr_scope) { - if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) { + if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT)) { u32t tmp_it = 0; for (const auto &it : vec_name_config_var) { if ((tmp_it = name_var.find(it)) != SIZE_MAX) { diff --git a/src/bweas.cpp b/src/bweas.cpp index 066e575..320a597 100644 --- a/src/bweas.cpp +++ b/src/bweas.cpp @@ -6,7 +6,7 @@ int main(int argv, char **args) { bweas::bwbuilder bw(argv, args); bw.set_logging(); bw.start(); - assist << std::string("Sec: " + std::to_string((double)(clock() - beg) / CLOCKS_PER_SEC)); + assist << std::to_string((double)(clock() - beg) / CLOCKS_PER_SEC); } catch (bwexception::bweas_exception &excp) { assist.call_err(excp.get_assist_err(), excp.what()); diff --git a/src/kernel/high_level/assistant.cpp b/src/kernel/high_level/assistant.cpp index dfff868..ff11f74 100644 --- a/src/kernel/high_level/assistant.cpp +++ b/src/kernel/high_level/assistant.cpp @@ -52,6 +52,7 @@ void assistant::add_err(std::string name_err, std::string desc) { err_s.emplace_back(name_err, desc, err_s.size()); } void assistant::call_err(std::string name_err) { + current_system_info = 1; const auto &it = std::find_if(err_s.begin(), err_s.end(), [name_err](const err &_err) { return _err.name_e == name_err; }); if (it == err_s.end()) { @@ -63,6 +64,7 @@ void assistant::call_err(std::string name_err) { exit(EXIT_FAILURE); } void assistant::call_err(std::string name_err, std::string addit) { + current_system_info = 1; const auto &it = std::find_if(err_s.begin(), err_s.end(), [name_err](const err &_err) { return _err.name_e == name_err; }); if (it == err_s.end()) { diff --git a/src/kernel/high_level/hook_linux_lib/decl_func_fbwhook.c b/src/kernel/high_level/hook_linux_lib/decl_func_fbwhook.c index f43e9a4..fc487d4 100644 --- a/src/kernel/high_level/hook_linux_lib/decl_func_fbwhook.c +++ b/src/kernel/high_level/hook_linux_lib/decl_func_fbwhook.c @@ -48,7 +48,7 @@ int lchown(const char *pathname, uid_t owner, gid_t group) { } void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) { HOOK_DETECTED_INF("mmap() call") - return HOOK_DETECTED; + return NULL; } int munmap(void *start, size_t length) { HOOK_DETECTED_INF("munmap() call") @@ -110,4 +110,4 @@ ssize_t sendmsg(int s, const struct msghdr *msg, int flags) { void init_hook() { HOOK_STATUS = 0; return; -} \ No newline at end of file +} From 58e0de2896af19639f4a6633c2708c5ea8fc4350 Mon Sep 17 00:00:00 2001 From: svec1 Date: Tue, 11 Feb 2025 21:48:20 +0000 Subject: [PATCH 02/38] add dependence file system, copyright --- CMakeLists.txt | 3 +- src/CMakeLists.txt | 4 +- src/bs/bw_defs.hpp | 29 +- src/bs/bwbuild_sys.cpp | 197 ++++---- src/bs/bwbuild_sys.hpp | 51 +- src/bs/bwcache_api.hpp | 32 +- src/bs/bwcache_fast.cpp | 97 +++- src/bs/bwcache_json.cpp | 20 +- src/bs/bwcache_lua.cpp | 54 ++- src/bs/bwconf_var.hpp | 9 +- src/bs/bwdepends_files.cpp | 42 ++ src/bs/bwdepends_files.hpp | 57 +++ src/bs/bwdepends_generator.hpp | 36 ++ src/bs/bwdepends_integral.hpp | 32 ++ src/bs/bwgenerator_api.hpp | 157 +++--- src/bs/bwgenerator_integral.cpp | 297 ++---------- src/bs/bwgenerator_integral.hpp | 26 +- src/bs/bwgenerator_lua.cpp | 81 ++-- src/bs/bwgntools.cpp | 11 +- src/bs/bwgntools.hpp | 13 +- src/bs/bwlang.hpp | 19 +- src/bs/{bwluatoolslang.hpp => bwluatools.cpp} | 450 +++++++++--------- src/bs/bwluatools.hpp | 71 +++ src/bs/bwmodule.cpp | 11 +- src/bs/bwmodule.hpp | 9 +- src/bs/bwpackage.cpp | 21 +- src/bs/bwpackage.hpp | 18 +- src/bs/lang/expression.hpp | 9 +- src/bs/lang/interpreter.cpp | 8 +- src/bs/lang/interpreter.hpp | 3 +- src/bs/lang/lexer.cpp | 2 +- src/bs/lang/parser_utility.cpp | 2 +- src/bs/lang/scope.hpp | 2 +- src/bs/lang/semantic_an.cpp | 2 +- src/bs/lang/static_linking_func.cpp | 45 +- src/bs/lang/static_struct.hpp | 43 +- src/bs/lang/token.hpp | 9 +- src/bs/tools/bwexception.hpp | 13 +- src/bs/tools/bwfile.hpp | 9 +- src/bs/tools/bwlua.hpp | 111 +++-- src/bs/tools/bwlz4.hpp | 9 +- src/bs/tools/call_cmd.hpp | 9 +- src/bweas.cpp | 9 +- src/kernel/high_level/assistant.cpp | 8 +- src/kernel/high_level/assistant.hpp | 9 +- 45 files changed, 1227 insertions(+), 922 deletions(-) create mode 100644 src/bs/bwdepends_files.cpp create mode 100644 src/bs/bwdepends_files.hpp create mode 100644 src/bs/bwdepends_generator.hpp create mode 100644 src/bs/bwdepends_integral.hpp rename src/bs/{bwluatoolslang.hpp => bwluatools.cpp} (70%) create mode 100644 src/bs/bwluatools.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 653f384..4199b19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ endif() set(BW_NAME_PRJ bweas) cmake_minimum_required(VERSION 3.20) + project(${BW_NAME_PRJ} LANGUAGES CXX C) option(USER_BUILD_LZ4 "Rep LZ4 on external" OFF) @@ -41,4 +42,4 @@ endif() if(BWEAS_TEST) enable_testing() add_subdirectory(test/) -endif() \ No newline at end of file +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5b6a46f..4be0d79 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -62,10 +62,12 @@ else() set(BWEAS_INCLUDE ${NLOHMANN_JSON_INCLUDE_INSTALL_DIR} ${LuaJIT_SRC_DIR} CACHE STRING "All header-files for bweas") endif() +set(BWEAS_INCLUDE ${BWEAS_INCLUDE} "kernel/high_level") + target_link_libraries(${BWEAS_SLIB} PRIVATE ${BWEAS_LIBS}) include_directories(${BWEAS_INCLUDE}) if(NOT WIN32) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernel/high_level/hook_linux_lib) target_link_libraries(${BWEAS_SLIB} PRIVATE bwhook_safe) -endif() \ No newline at end of file +endif() diff --git a/src/bs/bw_defs.hpp b/src/bs/bw_defs.hpp index 48c4fdb..d371920 100644 --- a/src/bs/bw_defs.hpp +++ b/src/bs/bw_defs.hpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the GNU General Public License 2.0 (GPL-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef BWDEFS__H #define BWDEFS__H @@ -27,7 +34,27 @@ "\n --help - outputs the syntax of the bweas call as well as its possible functions" \ "\n --version - outputs the version of bweas" +// bweas configuration file, defines all packages that should be loaded by the builder +#define JSON_CONFIG_FILE "bweas-config.json" + +// The current file of a project. It defines all target information +#define MAIN_FILE "bweasconf.txt" + +// Cache file, all information about all targets is saved there for quick access, which makes it possible not to +// reinterpret bweasconf.txt +#define CACHE_FILE "bwcache" + +// The name of the directory where the build files will be created +#define DIRWORK_ENV ".bweas" + +// The file in which all actions of the build system will be logged +#define LOG_FILE "bweas-last.log" + +// A postfix (extension) to the file name containing the names of the source file dependencies +#define DEPENDS_FILE_POSTFIX ".d" + namespace bweas { + using bwarg = std::pair; using bwargs = std::vector; using bwarg_files = std::pair>; @@ -91,4 +118,4 @@ class bwgenerator_excp : public bwbuilder_excp { } // namespace bweas -#endif \ No newline at end of file +#endif diff --git a/src/bs/bwbuild_sys.cpp b/src/bs/bwbuild_sys.cpp index 04a1a26..64bca85 100644 --- a/src/bs/bwbuild_sys.cpp +++ b/src/bs/bwbuild_sys.cpp @@ -1,24 +1,33 @@ -#include "bwbuild_sys.hpp" -#include "bwgenerator_integral.hpp" -#include "bwlang.hpp" -#include "lang/static_struct.hpp" +// +// BWEAS is distributed under the GNU General Public License 2.0 (GPL-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// #include #include #include #include -#include #include #include +#include "bwbuild_sys.hpp" +#include "bwdepends_files.hpp" +#include "bwdepends_generator.hpp" +#include "bwdepends_integral.hpp" +#include "bwgenerator_integral.hpp" +#include "bwlang.hpp" +#include "lang/static_struct.hpp" + +#include + using namespace bweas; using namespace bweas::bwexception; using mf = assistant::file::mode_file; using file_it = assistant::file_it; -bwlang _bwlang{MAIN_FILE}; - bwbuilder::bwbuilder(int argv, char **args) { if (!init_glob) { assist.add_err("BWS000", "Unable to open configuration file \'bweasconf.txt\'"); @@ -49,14 +58,7 @@ bwbuilder::bwbuilder(int argv, char **args) { } } -bwbuilder::~bwbuilder() { - if (_bwcache) - _bwcache->delete_cache(); - for (const auto &generator : generators) - generator.second->deleteGenerator(); -} - -void bwbuilder::handle_args(std::vector args) { +void bwbuilder::handle_args(std::vector &args) { args[0].erase(0, args[0].find_last_of("/\\") + 1); name_bweas_prg = args[0]; path_bweas_config = std::filesystem::current_path().string(); @@ -177,12 +179,12 @@ void bwbuilder::init() { throw bwbuilder_excp("Cache generator name expected", "005"); if (config_json["cache-gn"] == "fast_bwcache") - _bwcache = cache_api::base_bwcache::create_fast_bwcache(); + _bwcache = std::unique_ptr(cache_api::base_bwcache::create_fast_bwcache()); else if (config_json["cache-gn"] == "json_bwcache") - _bwcache = cache_api::base_bwcache::create_json_bwcache(); + _bwcache = std::unique_ptr(cache_api::base_bwcache::create_json_bwcache()); } else - _bwcache = cache_api::base_bwcache::create_fast_bwcache(); + _bwcache = std::unique_ptr(cache_api::base_bwcache::create_fast_bwcache()); if (config_json.contains("packages")) { if (!config_json["packages"].is_array()) @@ -191,13 +193,13 @@ void bwbuilder::init() { if (!package.value().is_string()) throw bwbuilder_excp("Package names are expected", "005"); bweas::bwpackage loaded_package; + std::string raw_data_package, path_to_package{assist.get_path_program() + "/packages/" + + (std::string)package.value() + BW_FORMAT_PACKAGE}; - std::string path_to_package = - assist.get_path_program() + "/packages/" + (std::string)package.value() + BW_FORMAT_PACKAGE; - std::string raw_data_package; file_it it_package = assist.open_file(path_to_package, mf::open::rb); if (!assist.exist_file(it_package)) throw bwbuilder_excp(path_to_package, "007"); + raw_data_package = assist.read_file(assist.get_ref_file(it_package), mf::input::read_binary); assist.close_file(it_package); @@ -205,20 +207,29 @@ void bwbuilder::init() { loaded_packages.push_back(loaded_package); if (_bwcache == NULL && loaded_package.cfg_package.cache.name_cache == config_json["cache-gn"]) - _bwcache = cache_api::base_bwcache::create_lua_bwcache(loaded_package.cfg_package.cache.src_lua_cache); + _bwcache = std::unique_ptr( + cache_api::base_bwcache::create_lua_bwcache(loaded_package.cfg_package.cache.src_lua_cache)); assist.next_output_success(); assist << " - [BWEAS]: The package was loaded successfully(" + std::to_string(raw_data_package.size()) + " bytes)"; } } - generators.emplace("bwgenerator", generator_api::base_generator::createGeneratorInt(generator::bwgenerator, - generator::bwfile_inputs)); + generators.emplace("bwgenerator", std::shared_ptr( + generator_api::base_generator::create_generator_int( + generator::bwgenerator, generator::bwbuild_graph_depends_file, + generator::bwget_input_files), + [](generator_api::base_generator *ptr) { ptr->_delete(); })); + for (const auto &package : loaded_packages) - for (const auto &generator : package.cfg_package.generators) + for (const auto &generator : package.cfg_package.generators) { generators.emplace(generator.name_generator, - generator_api::base_generator::createGeneratorLua(generator.src_lua_generator)); - + std::shared_ptr( + generator_api::base_generator::create_generator_lua(generator.src_lua_generator), + [](generator_api::base_generator *ptr) { ptr->_delete(); })); + if (generator.use_custom_build_graph_depends) + generators[generator.name_generator]->set_use_build_graph_depends(); + } for (auto &package : loaded_packages) { semantic_an::table_func tfuncs = module_manager.init_tsfunc(package.cfg_package.mds); for (const auto &func : tfuncs) @@ -261,7 +272,6 @@ void bwbuilder::start() { interpreter_start: run_interpreter(); gen_cache_target(); - imp_data_interpreter_for_bs(); } if (mode_bweas == mode_working::build || mode_bweas == mode_working::collect_cfg_w_build) { @@ -281,7 +291,11 @@ void bwbuilder::switch_output_log(u32t value) { } void bwbuilder::run_interpreter() { + + bwlang _bwlang{MAIN_FILE}; _bwlang.load_external_tfuncs(std::move(module_tfuncs)); + for (auto loaded_package : loaded_packages) + _bwlang.set_custom_ext_fields_project(loaded_package.cfg_package.custom_ext_fields_project); assist << " - [BWEAS]: Interpreting the configuration file..."; _bwlang.execute(); @@ -344,33 +358,59 @@ void bwbuilder::build_targets() { throw bwbuilder_excp("The provided generator as the primary for the current target was not found - " + out_targets[i].name_target + ": " + out_targets[i].name_generator, "002"); - auto ¤t_generator = generators[out_targets[i].name_generator]; - current_generator->set_const_data(call_components, global_extern_args); - current_generator->init(); - if (out_targets[i].prj.vec_templates.size() == 0) + else if (out_targets[i].prj.vec_templates.size() == 0) throw bwbuilder_excp("There are no templates for the target - " + out_targets[i].name_target, "002"); + std::string dir_target = path_bweas_to_build + "/" + out_targets[i].name_target; + double build_state = 0.f; + + bwqueue_templates bw_tcmd = create_queue_target_templates(out_targets[i]); + + auto ¤t_generator = generators[out_targets[i].name_generator]; + std::unique_ptr depends_files; + + bweas::generator_api::data_transfer data_t{&out_targets[i], &bw_tcmd, &call_components, &global_extern_args, + dir_target}; + if (!std::filesystem::is_directory(dir_target)) std::filesystem::create_directories(dir_target); - assist << " - [BWEAS]: Build {" + out_targets[i].name_target + "}"; + current_generator->init(); - bwqueue_templates bw_tcmd; - set_queue_templates(create_stack_target_templates(out_targets[i]), bw_tcmd); + if (current_generator->has_build_graph_depends()) + depends_files = + std::make_unique(current_generator, out_targets[i].prj.language, dir_target); + else + depends_files = std::make_unique(out_targets[i].prj.language, dir_target); + + for (const auto &name_file : out_targets[i].prj.src_files) { + if (!assist.exist_file(name_file)) + throw bwbuilder_excp("The target's source file was not found", "002"); + std::string name_depends_file = name_file + DEPENDS_FILE_POSTFIX; + if (assist.exist_file(name_depends_file)) + depends_files->build_graph_depends_file_string( + name_file, assist.read_file(assist.get_ref_file(assist.open_file(name_depends_file)))); + else + assist.write_file(assist.get_ref_file(assist.open_file(name_depends_file, mf::open::w)), + depends_files->get_string_depends_file(name_file)); + } + + depends_files->build_graphs_depends_files(out_targets[i].prj.src_files, out_targets[i].prj.include_paths); + data_t.dfiles = depends_files->get_graphs_depends_files(); + + assist << " - [BWEAS]: Build {" + out_targets[i].name_target + "}"; assist.switch_otp(0); - auto cmd_s = current_generator->gen_commands( - out_targets[i], bw_tcmd, dir_target, current_generator->input_files(out_targets[i], bw_tcmd, dir_target)); - assist.switch_otp(1); - double k_state = 0.f; + current_generator->get_input_files(data_t); + auto cmd_s = current_generator->generate_command(data_t); - for (const auto &cmd : cmd_s) { + assist.switch_otp(1); - k_state += 1.f / (double)cmd_s.size() * 100; + for (const auto &cmd : cmd_s) { assist.next_output_important(); - assist << "[" + std::to_string(k_state).erase(std::to_string((u32t)k_state).size() + 3, 4) + + assist << "[" + std::to_string(build_state).erase(std::to_string((u32t)build_state).size() + 3, 4) + "%]Compile - " + cmd.first; #if defined(WIN) @@ -378,14 +418,16 @@ void bwbuilder::build_targets() { #elif defined(UNIX) if (((int (*)(const char *))assist.get_realsystem_func())(cmd.second.c_str())) #endif - throw bwbuilder_excp("Failed build. Command execution error - " + cmd.second, "004"); + throw bwbuilder_excp("Failed build. Command execution error: \n" + cmd.second, "004"); + + build_state += 1.f / (double)cmd_s.size() * 100; } } } -std::stack bwbuilder::create_stack_target_templates(const var::struct_sb::target_out &target) { +bwqueue_templates bwbuilder::create_queue_target_templates(const var::struct_sb::target_out &target) { std::vector vec_templates_tmp; - std::stack stack_templates; + bwqueue_templates target_queue_templates; for (u32t i = 0; i < target.prj.vec_templates.size(); ++i) { for (u32t j = 0; j < templates.size(); ++j) @@ -403,69 +445,26 @@ std::stack bwbuilder::create_stack_target_templates(const var::stru var::struct_sb::target_t_str(target.target_t), "002"); - stack_templates.push(it_template->name); + target_queue_templates.push_back(*it_template); for (u32t i = 0; i < it_template->name_accept_params.size(); ++i) - recovery_stack_templates(vec_templates_tmp, it_template->name_accept_params[i], stack_templates); + recovery_queue_target_templates(vec_templates_tmp, it_template->name_accept_params[i], target_queue_templates); - return stack_templates; + std::reverse(target_queue_templates.begin(), target_queue_templates.end()); + + return target_queue_templates; } -u32t bwbuilder::recovery_stack_templates(std::vector &vec_templates, - const std::string &name_internal_param, - std::stack &stack_templates) { +void bwbuilder::recovery_queue_target_templates(std::vector &vec_templates, + const std::string &name_internal_param, + bwqueue_templates &target_queue_templates) { const auto &it = find_if(vec_templates.begin(), vec_templates.end(), [name_internal_param](const var::struct_sb::template_command &_template) { return _template.returnable == name_internal_param; }); if (it == vec_templates.end()) - return 1; + return; - stack_templates.push(it->name); + target_queue_templates.push_back(*it); for (u32t i = 0; i < it->name_accept_params.size(); ++i) - recovery_stack_templates(vec_templates, it->name_accept_params[i], stack_templates); - - return 0; -} -void bwbuilder::set_queue_templates(std::stack &&stack_target_templates, - bwqueue_templates &target_queue_templates) { - while (stack_target_templates.size()) { - const auto &it_templates = find_if(templates.begin(), templates.end(), - [stack_target_templates](const var::struct_sb::template_command &tcmd) { - return tcmd.name == stack_target_templates.top(); - }); - target_queue_templates.push_back(*it_templates); - stack_target_templates.pop(); - } -} - -void bwbuilder::imp_data_interpreter_for_bs() { - const auto &global_templates = - _bwlang.get_global_scope().get_vector_variables_t(); - std::unordered_set name_global_external_args; - - for (const auto &global_template_it : global_templates) { - for (const auto &arg : global_template_it.second.args) - if (arg.arg_t == var::struct_sb::template_command::arg::type::extglobal) - name_global_external_args.emplace(arg.str_arg); - templates.push_back(global_template_it.second); - } - - const auto &global_call_components = - _bwlang.get_global_scope().get_vector_variables_t(); - for (const auto &global_call_component : global_call_components) - call_components.push_back(global_call_component.second); - - const auto &string_variables = _bwlang.get_global_scope().get_vector_variables_t(); - for (const auto &name_global_external_arg : name_global_external_args) { - const auto &ref_extern_arg = - find_if(string_variables.begin(), string_variables.end(), - [name_global_external_arg](const std::pair &str_var) { - return str_var.first == name_global_external_arg; - }); - if (_bwlang.get_global_scope().what_type(ref_extern_arg->second) != 2) - throw bwbuilder_excp( - "The parameter reference(name) points to a non-existent variable - " + ref_extern_arg->second, "002"); - const auto &extern_arg = _bwlang.get_global_scope().get_var_value(ref_extern_arg->second); - global_extern_args.push_back(std::pair(ref_extern_arg->first, extern_arg)); - } + recovery_queue_target_templates(vec_templates, it->name_accept_params[i], target_queue_templates); } diff --git a/src/bs/bwbuild_sys.hpp b/src/bs/bwbuild_sys.hpp index 63adf92..24c918d 100644 --- a/src/bs/bwbuild_sys.hpp +++ b/src/bs/bwbuild_sys.hpp @@ -1,32 +1,23 @@ +// +// BWEAS is distributed under the GNU General Public License 2.0 (GPL-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef BWBUILD_SYS__H #define BWBUILD_SYS__H #include "../mdef.hpp" +#include + #include "bw_defs.hpp" #include "bwcache_api.hpp" #include "bwgenerator_api.hpp" #include "bwmodule.hpp" #include "bwpackage.hpp" -#include - -// bweas configuration file, defines all packages that should be loaded by the builder -#define JSON_CONFIG_FILE "bweas-config.json" - -// The current file of a project. It defines all target information -#define MAIN_FILE "bweasconf.txt" - -// Cache file, all information about all targets is saved there for quick access, which makes it possible not to -// reinterpret bweasconf.txt -#define CACHE_FILE "bwcache" - -// The name of the directory where the build files will be created -#define DIRWORK_ENV ".bweas" - -// The file in which all actions of the build system will be logged -#define LOG_FILE "bweas-last.log" - namespace bweas { // Builder class. It is a holistic program. It has operating modes (mode_working), which itself determines by passing @@ -40,7 +31,7 @@ class bwbuilder final { bwbuilder(const bwbuilder &) = delete; bwbuilder &operator=(bwbuilder &&) = delete; - ~bwbuilder(); + ~bwbuilder() = default; public: // all possible bweas operating modes @@ -81,7 +72,7 @@ class bwbuilder final { // it exists) // --package - creates a bweas package based on the transferred files (json config, lua - generator script) // - void handle_args(std::vector args); + void handle_args(std::vector &args); // Creates a bweas package based on the provided package configuration json file u32t create_package(std::string path_json_config_package); // loads the bweas json config @@ -111,29 +102,23 @@ class bwbuilder final { // Deserializes the bweas cache file void deserl_cache(); - // Imports all call templates and components declared in bweasconf.txt, which the interpreter also created - void imp_data_interpreter_for_bs(); - private: // Creates a stack of templates for the correct sequential generation of commands(for every targets) - std::stack create_stack_target_templates(const var::struct_sb::target_out &target); + bwqueue_templates create_queue_target_templates(const var::struct_sb::target_out &target); // Recursive function, for create_stack_target_templates - u32t recovery_stack_templates(std::vector &vec_templates, - const std::string &name_internal_param, std::stack &stack_templates); - - // Converts the stack into an ordered pattern vector - void set_queue_templates(std::stack &&stack_target_templates, - bwqueue_templates &target_queue_templates); + void recovery_queue_target_templates(std::vector &vec_templates, + const std::string &name_internal_param, + bwqueue_templates &queue_target_templates); private: - cache_api::base_bwcache *_bwcache{NULL}; + std::unique_ptr _bwcache; semantic_an::table_func module_tfuncs; module::module_mg module_manager; std::vector loaded_packages; - std::map generators; + std::map> generators; std::vector out_targets; std::vector templates; @@ -152,4 +137,4 @@ class bwbuilder final { }; } // namespace bweas -#endif \ No newline at end of file +#endif diff --git a/src/bs/bwcache_api.hpp b/src/bs/bwcache_api.hpp index cd82b50..125feeb 100644 --- a/src/bs/bwcache_api.hpp +++ b/src/bs/bwcache_api.hpp @@ -1,20 +1,30 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef BWCACHE__H #define BWCACHE__H #include "bw_defs.hpp" -#include "tools/bwlua.hpp" +#include "bwluatools.hpp" -#define NAME_FUNCTION_GENCACHE "create_cache" -#define DEFINITION_FUNCTION_GENCACHE \ ->, bwlua::lua::array>, bwlua::lua::array>, bwlua::lua::array>> +#define NAME_FUNCTION_GENERATE_CACHE_LUA "create_cache" +#define DEFINITION_FUNCTION_GENERATE_CACHE_LUA \ + std::string, bwluatools::ref>>, \ + bwluatools::ref>>, \ + bwluatools::ref>>, \ + bwluatools::ref>> -#define NAME_FUNCTION_GETDATA_CACHE "get_cache_data" -#define DEFINITION_FUNCTION_GETDATA_CACHE +#define NAME_FUNCTION_GET_DATA_CACHE_LUA "get_cache_data" +#define DEFINITION_FUNCTION_GET_DATA_CACHE_LUA void, bwluatools::nil -#define NAME_VARIABLE_TARGETS_F_EXTERN "targets" -#define NAME_VARIABLE_TEMPLATES_F_EXTERN "templates" -#define NAME_VARIABLE_CCOMPONENTS_F_EXTERN "call_components" -#define NAME_VARIABLE_GEARGS_F_EXTERN "global_external_args" +#define NAME_VARIABLE_TARGETS_F_EXTERN_LUA "targets" +#define NAME_VARIABLE_TEMPLATES_F_EXTERN_LUA "templates" +#define NAME_VARIABLE_CCOMPONENTS_F_EXTERN_LUA "call_components" +#define NAME_VARIABLE_GEARGS_F_EXTERN_LUA "global_external_args" namespace bweas { @@ -121,4 +131,4 @@ base_bwcache *base_bwcache::create_lua_bwcache(std::string src_lua) { } // namespace bweas -#endif \ No newline at end of file +#endif diff --git a/src/bs/bwcache_fast.cpp b/src/bs/bwcache_fast.cpp index ca796ad..fa17e3f 100644 --- a/src/bs/bwcache_fast.cpp +++ b/src/bs/bwcache_fast.cpp @@ -1,7 +1,14 @@ -#include "bwcache_api.hpp" +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// #include +#include "bwcache_api.hpp" + using namespace bweas; using namespace cache_api; using namespace bweas::bwexception; @@ -30,20 +37,21 @@ std::string fast_bwcache::create_cache() { for (i32t i = 0; i < out_targets.size(); ++i) { char *prj_v = (char *)&out_targets[i]; serel_target_tmp += std::to_string(out_targets[i].prj.src_files.size()) + " " + + std::to_string(out_targets[i].prj.include_paths.size()) + " " + std::to_string(out_targets[i].prj.vec_templates.size()) + " " + + std::to_string(out_targets[i].prj.custom_ext_fields.size()) + " " + std::to_string(out_targets[i].target_vec_libs.size()) + " "; for (u32t j = 0; j < sizeof(var::struct_sb::project); j += sizeof(std::string)) { // version project if (j == sizeof(std::string)) { serel_target_tmp += (*(var::struct_sb::version *)(prj_v + j)).get_str_version() + " " + - std::to_string(*(unsigned long *)(prj_v + j + sizeof(var::struct_sb::version))) + - " "; - j += sizeof(var::struct_sb::version) + sizeof(size_t); + *(std::string *)(prj_v + j + sizeof(var::struct_sb::version)) + " "; + j += sizeof(var::struct_sb::version) + sizeof(std::string); } // standart c - else if (j == sizeof(std::string) * 7 + sizeof(var::struct_sb::version) + sizeof(size_t)) { + else if (j == sizeof(std::string) * 7 + sizeof(var::struct_sb::version) + sizeof(std::string)) { serel_target_tmp += std::to_string(*(i32t *)(prj_v + j)) + " " + std::to_string(*(i32t *)(prj_v + j + sizeof(i32t))) + " " + std::to_string(*(bool *)(prj_v + j + sizeof(i32t) * 2)) + " "; @@ -56,10 +64,14 @@ std::string fast_bwcache::create_cache() { } for (u32t j = 0; j < out_targets[i].prj.src_files.size(); ++j) serel_target_tmp += out_targets[i].prj.src_files[j] + " "; + for (u32t j = 0; j < out_targets[i].prj.include_paths.size(); ++j) + serel_target_tmp += out_targets[i].prj.include_paths[j] + " "; for (u32t j = 0; j < out_targets[i].prj.vec_templates.size(); ++j) { used_templates.emplace(out_targets[i].prj.vec_templates[j]); serel_target_tmp += out_targets[i].prj.vec_templates[j] + " "; } + for (auto it : out_targets[i].prj.custom_ext_fields) + serel_target_tmp += it.first + " " + it.second + " "; serel_target_tmp += var::struct_sb::target_t_str(out_targets[i].target_t) + " " + var::struct_sb::cfg_str(out_targets[i].target_cfg) + " " + out_targets[i].name_target + @@ -122,16 +134,18 @@ const base_bwcache::cache_data &fast_bwcache::get_cache_data(std::string cache_s var::struct_sb::template_command::arg arg_tmp; var::struct_sb::call_component ccmp_tmp; - std::string str_tmp; + std::string str_tmp, str_tmp_key; i32t count_word = 0, offset_byte_prj = 0, offset_byte_ccmp = 0; - i32t size_src_files = 0, size_vec_templates = 0, size_vec_libs = 0; + i32t size_src_files = 0, size_include_paths, size_vec_templates = 0, size_custom_ext_fields, size_vec_libs = 0; i32t size_templates = 0; i32t size_internal_args = 0, size_external_args = 0, size_call_components = 0, size_global_extern_args = 0; char *tproj_p = (char *)&trg_tmp.prj; char *ccmp_p = (char *)&ccmp_tmp; + bool is_beg_custom_field = 0; + bool open_sk = 0; bool enum_templates = 0; bool enum_call_component = 0; @@ -149,7 +163,7 @@ const base_bwcache::cache_data &fast_bwcache::get_cache_data(std::string cache_s continue; } - if (cache_str[i] == ' ' && !open_sk) { + if (cache_str[i] == ' ' && !str_tmp.empty() && !open_sk) { next_word: ++count_word; if (enum_global_extern_args) { @@ -227,41 +241,74 @@ const base_bwcache::cache_data &fast_bwcache::get_cache_data(std::string cache_s if (count_word == 1) size_src_files = std::stoi(str_tmp); else if (count_word == 2) - size_vec_templates = std::stoi(str_tmp); + size_include_paths = std::stoi(str_tmp); else if (count_word == 3) + size_vec_templates = std::stoi(str_tmp); + else if (count_word == 4) + size_custom_ext_fields = std::stoi(str_tmp); + else if (count_word == 5) size_vec_libs = std::stoi(str_tmp); - else if (count_word > 3) { - if (count_word == 6 || (count_word >= 13 && count_word <= 15)) { + else if (count_word > 6) { + if (count_word >= 16 && count_word <= 17) { *(i32t *)(tproj_p + offset_byte_prj) = std::atoll(str_tmp.c_str()); offset_byte_prj += sizeof(i32t); } - else if (count_word == 5) { + else if (count_word == 7) { trg_tmp.prj.version_project = str_tmp; offset_byte_prj += sizeof(var::struct_sb::version); } + else if (count_word == 8) { + trg_tmp.prj.language = str_tmp; + offset_byte_prj += sizeof(std::string); + } else { - - if (count_word >= 16 && count_word < 16 + size_src_files) + if (count_word >= 18 && count_word < 18 + size_src_files) trg_tmp.prj.src_files.push_back(str_tmp); - else if (count_word >= 16 + size_src_files && - count_word < 16 + size_src_files + size_vec_templates) { + else if (count_word >= 18 + size_src_files && + count_word < 18 + size_src_files + size_include_paths) { + if (str_tmp != "null") + trg_tmp.prj.include_paths.push_back(str_tmp); + } + else if (count_word >= 18 + size_src_files + size_include_paths && + count_word < 18 + size_src_files + size_include_paths + size_vec_templates) { if (str_tmp != "null") trg_tmp.prj.vec_templates.push_back(str_tmp); } - else if (count_word == 16 + size_src_files + size_vec_templates) + else if (count_word >= 18 + size_src_files + size_include_paths + size_vec_templates && + count_word < 18 + size_src_files + size_include_paths + size_vec_templates + + size_custom_ext_fields) { + if (str_tmp == "null") + ; + else if (is_beg_custom_field = !is_beg_custom_field) { + trg_tmp.prj.custom_ext_fields[str_tmp] = ""; + str_tmp_key = str_tmp; + --count_word; + } + else + trg_tmp.prj.custom_ext_fields.find(str_tmp_key)->second = str_tmp; + } + else if (count_word == 18 + size_src_files + size_include_paths + size_vec_templates + + size_custom_ext_fields) trg_tmp.target_t = var::struct_sb::to_type_target(str_tmp); - else if (count_word == 16 + size_src_files + size_vec_templates + 1) + else if (count_word == 18 + size_src_files + size_include_paths + size_vec_templates + + size_custom_ext_fields + 1) trg_tmp.target_cfg = var::struct_sb::to_cfg(str_tmp); - else if (count_word == 16 + size_src_files + size_vec_templates + 2) + else if (count_word == 18 + size_src_files + size_include_paths + size_vec_templates + + size_custom_ext_fields + 2) trg_tmp.name_target = str_tmp; - else if (count_word == 16 + size_src_files + size_vec_templates + 3) + else if (count_word == 18 + size_src_files + size_include_paths + size_vec_templates + + size_custom_ext_fields + 3) trg_tmp.name_generator = str_tmp; - else if (count_word == 16 + size_src_files + size_vec_templates + 4) + else if (count_word == 18 + size_src_files + size_include_paths + size_vec_templates + + size_custom_ext_fields + 4) trg_tmp.version_target = str_tmp; - else if (count_word >= 16 + size_src_files + size_vec_templates + 5 && - count_word < 16 + size_src_files + size_vec_templates + 5 + size_vec_libs) + else if (count_word >= 18 + size_src_files + size_include_paths + size_vec_templates + + size_custom_ext_fields + 5 && + count_word < 18 + size_src_files + size_include_paths + size_vec_templates + + size_custom_ext_fields + 5 + size_vec_libs) trg_tmp.target_vec_libs.push_back(str_tmp); - else if (count_word == 16 + size_src_files + size_vec_templates + 5 + size_vec_libs) { + else if (count_word == 18 + size_src_files + size_include_paths + size_vec_templates + + size_custom_ext_fields + 5 + size_vec_libs) { _cache_data.targets_o.push_back(trg_tmp); trg_tmp.target_vec_libs = {}; @@ -302,4 +349,4 @@ const base_bwcache::cache_data &fast_bwcache::get_cache_data(std::string cache_s } return _cache_data; -} \ No newline at end of file +} diff --git a/src/bs/bwcache_json.cpp b/src/bs/bwcache_json.cpp index 24927eb..036cfa4 100644 --- a/src/bs/bwcache_json.cpp +++ b/src/bs/bwcache_json.cpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #include "bwcache_api.hpp" #include @@ -31,7 +38,7 @@ std::string json_bwcache::create_cache() { {"project", {{"name", target.prj.name_project}, {"version", target.prj.version_project.get_str_version()}, - {"lang", var::struct_sb::lang_str(target.prj.lang)}, + {"lang", target.prj.language}, {"path_compiler", target.prj.path_compiler}, {"path_linker", target.prj.path_linker}, {"release_flags_compiler", target.prj.rflags_compiler}, @@ -41,8 +48,10 @@ std::string json_bwcache::create_cache() { {"std_c", target.prj.standart_c}, {"std_cpp", target.prj.standart_cpp}, {"files", target.prj.src_files}, + {"include_paths", target.prj.include_paths}, {"use_it_templates", target.prj.use_it_templates}, - {"templates", target.prj.vec_templates}}}}; + {"templates", target.prj.vec_templates}, + {"custom_extension_fields", target.prj.custom_ext_fields}}}}; for (const auto &_template : _cache_data.templates) { cache_data["templates"][_template.name] = {{"name_call_component", _template.name_call_component}, @@ -81,7 +90,7 @@ const base_bwcache::cache_data &json_bwcache::get_cache_data(std::string cache_s const auto &prj = fields["project"]; target_o_tmp.prj.name_project = prj["name"]; target_o_tmp.prj.version_project = (std::string)prj["version"]; - target_o_tmp.prj.lang = var::struct_sb::to_lang(prj["lang"]); + target_o_tmp.prj.language = prj["lang"]; target_o_tmp.prj.path_compiler = prj["path_compiler"]; target_o_tmp.prj.path_linker = prj["path_linker"]; target_o_tmp.prj.rflags_compiler = prj["release_flags_compiler"]; @@ -91,9 +100,10 @@ const base_bwcache::cache_data &json_bwcache::get_cache_data(std::string cache_s target_o_tmp.prj.standart_c = prj["std_c"]; target_o_tmp.prj.standart_cpp = prj["std_cpp"]; target_o_tmp.prj.src_files = prj["files"]; + target_o_tmp.prj.include_paths = prj["include_paths"]; target_o_tmp.prj.use_it_templates = prj["use_it_templates"]; target_o_tmp.prj.vec_templates = prj["templates"]; - + target_o_tmp.prj.custom_ext_fields = prj["custom_extension_fields"]; _cache_data.targets_o.push_back(target_o_tmp); } @@ -132,4 +142,4 @@ const base_bwcache::cache_data &json_bwcache::get_cache_data(std::string cache_s catch (std::exception &what) { throw bwcache_excp(what.what(), "000"); } -} \ No newline at end of file +} diff --git a/src/bs/bwcache_lua.cpp b/src/bs/bwcache_lua.cpp index 2b6d0f4..6a3e3d8 100644 --- a/src/bs/bwcache_lua.cpp +++ b/src/bs/bwcache_lua.cpp @@ -1,5 +1,12 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #include "bwcache_api.hpp" -#include "bwluatoolslang.hpp" +#include "bwluatools.hpp" using namespace bweas; using namespace cache_api; @@ -15,9 +22,9 @@ lua_bwcache::lua_bwcache(std::string src_lua) { } lua.create(src_lua); - if (!lua.is_function(NAME_FUNCTION_GENCACHE)) + if (!lua.is_function(NAME_FUNCTION_GENERATE_CACHE_LUA)) throw bwcache_excp("", "001"); - else if (!lua.is_function(NAME_FUNCTION_GETDATA_CACHE)) + else if (!lua.is_function(NAME_FUNCTION_GET_DATA_CACHE_LUA)) throw bwcache_excp("", "002"); } @@ -26,20 +33,20 @@ void lua_bwcache::delete_cache() { } std::string lua_bwcache::create_cache() { - std::vector> ltargets_o; - std::vector> ltcmd_s; - std::vector> lccmp_s; + std::vector> ltargets_o; + std::vector> ltcmd_s; + std::vector> lccmp_s; for (const auto <arget_o : _cache_data.targets_o_p != nullptr ? *_cache_data.targets_o_p : _cache_data.targets_o) - ltargets_o.push_back(lua_tools::conv_to_table(ltarget_o)); + ltargets_o.push_back(bwluatools::conv_to_table(ltarget_o)); for (const auto <cmd : _cache_data.templates) - ltcmd_s.push_back(lua_tools::conv_to_table(ltcmd)); + ltcmd_s.push_back(bwluatools::conv_to_table(ltcmd)); for (const auto &lccmp : _cache_data.call_components) - lccmp_s.push_back(lua_tools::conv_to_table(lccmp)); + lccmp_s.push_back(bwluatools::conv_to_table(lccmp)); try { - return lua.call_function DEFINITION_FUNCTION_GENCACHE(NAME_FUNCTION_GENCACHE, ltargets_o, ltcmd_s, lccmp_s, - _cache_data.global_external_args); + return lua.call_function( + NAME_FUNCTION_GENERATE_CACHE_LUA, ltargets_o, ltcmd_s, lccmp_s, _cache_data.global_external_args); } catch (std::exception &what) { throw bwcache_excp(what.what(), "000"); @@ -48,33 +55,34 @@ std::string lua_bwcache::create_cache() { const base_bwcache::cache_data &lua_bwcache::get_cache_data(std::string cache_str) { - std::vector> ltargets_o; - std::vector> ltcmd_s; - std::vector> lccmp_s; + std::vector> ltargets_o; + std::vector> ltcmd_s; + std::vector> lccmp_s; std::vector> lglobal_external_args; try { - lua.call_function DEFINITION_FUNCTION_GETDATA_CACHE(NAME_FUNCTION_GETDATA_CACHE, {}); + lua.call_function(NAME_FUNCTION_GET_DATA_CACHE_LUA, {}); ltargets_o = - lua[NAME_VARIABLE_TARGETS_F_EXTERN].getval>>(); - ltcmd_s = lua[NAME_VARIABLE_TEMPLATES_F_EXTERN].getval>>(); + lua[NAME_VARIABLE_TARGETS_F_EXTERN_LUA].getval>>(); + ltcmd_s = + lua[NAME_VARIABLE_TEMPLATES_F_EXTERN_LUA].getval>>(); lccmp_s = - lua[NAME_VARIABLE_CCOMPONENTS_F_EXTERN].getval>>(); + lua[NAME_VARIABLE_CCOMPONENTS_F_EXTERN_LUA].getval>>(); lglobal_external_args = - lua[NAME_VARIABLE_GEARGS_F_EXTERN].getval>>(); + lua[NAME_VARIABLE_GEARGS_F_EXTERN_LUA].getval>>(); } catch (std::exception &what) { throw bwcache_excp(what.what(), "000"); } for (auto <arget_o : ltargets_o) - _cache_data.targets_o.push_back(lua_tools::conv_to_target(ltarget_o)); + _cache_data.targets_o.push_back(bwluatools::conv_to_target(ltarget_o)); for (auto <cmd : ltcmd_s) - _cache_data.templates.push_back(lua_tools::conv_to_template(ltcmd)); + _cache_data.templates.push_back(bwluatools::conv_to_template(ltcmd)); for (auto &lccmp : lccmp_s) - _cache_data.call_components.push_back(lua_tools::conv_to_call_components(lccmp)); + _cache_data.call_components.push_back(bwluatools::conv_to_call_components(lccmp)); _cache_data.global_external_args = lglobal_external_args; return _cache_data; -} \ No newline at end of file +} diff --git a/src/bs/bwconf_var.hpp b/src/bs/bwconf_var.hpp index d56744a..0e85cb2 100644 --- a/src/bs/bwconf_var.hpp +++ b/src/bs/bwconf_var.hpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef BWCONF_VAR__H #define BWCONF_VAR__H @@ -50,4 +57,4 @@ #endif -#endif \ No newline at end of file +#endif diff --git a/src/bs/bwdepends_files.cpp b/src/bs/bwdepends_files.cpp new file mode 100644 index 0000000..239aef0 --- /dev/null +++ b/src/bs/bwdepends_files.cpp @@ -0,0 +1,42 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + +#include + +#include "bwdepends_files.hpp" + +bweas::bwdepends_files::depends_map &bweas::bwdepends_files::build_graphs_depends_files( + const std::vector &src_files, const std::vector &include_paths) { + for (const auto &file : src_files) { + if (mdepends.find(file) == mdepends.end()) + mdepends[file] = build_graph_depends_file(file, include_paths); + } + return mdepends; +} +bweas::bwdepends_files::depends_map &bweas::bwdepends_files::build_graph_depends_file_string(std::string name_file, + std::string depends_file) { + auto it_depends_file = mdepends.find(mdepends[name_file].size() ? name_file : name_file); + i32t it = 0; + while ((it = depends_file.find("\n")) != depends_file.npos) { + std::string name_dependences; + for (u32t i = 0; i < it; ++i) + name_dependences += depends_file[i]; + it_depends_file->second.insert(name_dependences); + depends_file.erase(0, it + 1); + } + return mdepends; +} +bweas::bwdepends_files::depends_map &bweas::bwdepends_files::get_graphs_depends_files() { + return mdepends; +} +std::string bweas::bwdepends_files::get_string_depends_file(std::string name_file) { + std::string str; + for (const auto &dependence : mdepends[name_file]) + str += dependence + "\n"; + + return str; +} diff --git a/src/bs/bwdepends_files.hpp b/src/bs/bwdepends_files.hpp new file mode 100644 index 0000000..7a60c8b --- /dev/null +++ b/src/bs/bwdepends_files.hpp @@ -0,0 +1,57 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + +#ifndef BWDEPENDS_FILES__H +#define BWDEPENDS_FILES__H + +#include +#include + +#include +#include +#include + +namespace bweas { + +// File dependency system interface, defines specific functions +class bwdepends_files { + public: + bwdepends_files(const std::string_view _language, const std::string_view _work_directory) + : language(_language), work_directory(_work_directory) { + } + ~bwdepends_files() = default; + + public: + // file, dependencies + using depends_file = std::pair>; + using depends_map = std::unordered_map; + + // Dependency graphs of source files are built + depends_map &build_graphs_depends_files(const std::vector &src_files, + const std::vector &include_paths); + // depends_file - list of file dependencies(name_file) + depends_map &build_graph_depends_file_string(std::string name_file, std::string depends_file); + + depends_map &get_graphs_depends_files(); + + public: + // Returns all dependent files of the transmitted file as a string + std::string get_string_depends_file(std::string name_file); + + protected: + virtual std::unordered_set build_graph_depends_file(std::string_view name_file, + const std::vector &include_paths) = 0; + + protected: + std::string language; + std::string work_directory; + + private: + depends_map mdepends; +}; +} // namespace bweas +#endif diff --git a/src/bs/bwdepends_generator.hpp b/src/bs/bwdepends_generator.hpp new file mode 100644 index 0000000..4fb41e7 --- /dev/null +++ b/src/bs/bwdepends_generator.hpp @@ -0,0 +1,36 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + +#ifndef BWDEPENDS_GENERATOR__H +#define BWDEPENDS_GENERATOR__H + +#include "bwgenerator_api.hpp" + +namespace bweas { + +class bwdepends_generator : public bweas::bwdepends_files { + public: + bwdepends_generator(std::shared_ptr _generator, const std::string_view language, + const std::string_view work_directory) + : generator(_generator), bweas::bwdepends_files(language, work_directory) { + } + ~bwdepends_generator() = default; + + public: + std::unordered_set build_graph_depends_file( + std::string_view name_file, const std::vector &include_paths) override final; + + private: + std::shared_ptr generator; +}; + +std::unordered_set bweas::bwdepends_generator::build_graph_depends_file( + std::string_view name_file, const std::vector &include_paths) { + return generator->build_graph_depends_file(language, name_file, work_directory, include_paths); +} +} // namespace bweas +#endif diff --git a/src/bs/bwdepends_integral.hpp b/src/bs/bwdepends_integral.hpp new file mode 100644 index 0000000..208787c --- /dev/null +++ b/src/bs/bwdepends_integral.hpp @@ -0,0 +1,32 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + +#ifndef BWDEPENDS_INTEGRAL__H +#define BWDEPENDS_INTEGRAL__H + +#include "bwdepends_files.hpp" +#include "bwgenerator_integral.hpp" + +namespace bweas { +class bwdepends_integral : public bwdepends_files { + public: + bwdepends_integral(const std::string_view language, const std::string_view work_directory) + : bwdepends_files(language, work_directory) { + } + ~bwdepends_integral() = default; + + public: + std::unordered_set build_graph_depends_file( + std::string_view name_file, const std::vector &include_paths) override final; +}; +} // namespace bweas + +std::unordered_set bweas::bwdepends_integral::build_graph_depends_file( + std::string_view name_file, const std::vector &include_paths) { +} + +#endif diff --git a/src/bs/bwgenerator_api.hpp b/src/bs/bwgenerator_api.hpp index bf34219..a021188 100644 --- a/src/bs/bwgenerator_api.hpp +++ b/src/bs/bwgenerator_api.hpp @@ -1,20 +1,68 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef BWGENERATOR__H #define BWGENERATOR__H -#include "bw_defs.hpp" -#include "tools/bwlua.hpp" - -#define NAME_FUNCTION_GENLUA "generate" -#define DEFINITION_FUNCTION_GENLUA \ -, bwlua::lua::table>> +#include -#define NAME_FUNCTION_FILECLUA "get_files_input" -#define DEFINITION_FUNCTION_FILECLUA \ ->, bwlua::lua::table, std::vector>> +#include "bw_defs.hpp" +#include "bwdepends_files.hpp" +#include "bwluatools.hpp" + +// Accepts only an array of input files. However, the bass generator API creates global configuration variables that the +// function can access (target - "CURRENT_TARGET", templates - "CURRENT_QUEUE_TEMPLATES", call components - "CCMPS", and +// the path of the working directory - "CURRENT_DIR") +#define NAME_FUNCTION_GENERATE_COMMAND_LUA "generate" +#define DEFINITION_FUNCTION_GENERATE_COMMAND_LUA \ + bwluatools::table, \ + bwluatools::ref>> + +// Accepts a name file, directory work +#define NAME_FUNCTION_BUILD_DEPENDS_LUA "build_graph_depends_file" +#define DEFINITION_FUNCTION_BUILD_DEPENDS_LUA \ + bwluatools::array, std::string_view, std::string_view, std::string_view, \ + bwluatools::ref> + +// Accepts a target, its templates, and a global list of file trees (It can also use the "CCMPS" global variable) +#define NAME_FUNCTION_GET_INPUT_FILE_LUA "get_input_files" +#define DEFINITION_FUNCTION_GET_INPUT_FILE_LUA \ + bwluatools::table>, \ + bwluatools::ref>, \ + bwluatools::ref>>, \ + bwluatools::ref>> namespace bweas { namespace generator_api { + +// name_templates, name files +using files_input = std::map>; +// name_input_file, command +using gen_command = std::map; + +// A temporary structure that allows you to transfer data to the generator and its sub-functions +struct data_transfer { + data_transfer(var::struct_sb::target_out *_trg, bwqueue_templates *_trg_templates, + std::vector *_ccmp_s, bwargs *_global_extern_args, + std::string _work_directory) + : trg(_trg), trg_templates(_trg_templates), ccmp_s(_ccmp_s), global_extern_args(_global_extern_args), + work_directory(_work_directory) { + } + var::struct_sb::target_out *const trg; + bwqueue_templates *const trg_templates; + std::vector *const ccmp_s; + bwargs *const global_extern_args; + + bwdepends_files::depends_map dfiles; + files_input ifiles; + std::string work_directory; +}; + namespace gninterface { // Interface class that defines the structure of generator classes @@ -23,18 +71,17 @@ class interface_generator { interface_generator &operator=(const interface_generator &) = delete; public: - virtual void deleteGenerator() = 0; + virtual void _delete() = 0; // Generator initialization function virtual void init() = 0; - // Returns a list of files of the passed target that need to be compiled - virtual std::map> input_files(const var::struct_sb::target_out &target, - const bwqueue_templates &target_queue_templates, - std::string) = 0; + // Implementing a function for the file dependency system, returns a list of dependent files(graph) + virtual std::unordered_set build_graph_depends_file(std::string_view, std::string_view, + std::string_view, std::vector) = 0; + // Initializes(defines) files that should be compiled (recompiled) for the current target + virtual void get_input_files(data_transfer &) = 0; // The generator function returns the commands generated by it in the order of the templates used for the // transmitted target - virtual std::map gen_commands(const var::struct_sb::target_out &, bwqueue_templates &, - std::string, - std::map>) = 0; + virtual gen_command generate_command(data_transfer &) = 0; protected: virtual ~interface_generator() = default; @@ -42,13 +89,10 @@ class interface_generator { } // namespace gninterface -using func_generator = std::map (*)(const var::struct_sb::target_out &, bwqueue_templates &, - const std::vector &, - std::map>, - std::string); -using func_get_files_input = std::map> (*)( - const var::struct_sb::target_out &, const bwqueue_templates &, - const std::vector &ccmp_p, std::string); +using func_generator = gen_command (*)(data_transfer &); +using func_build_graph_depends_file = std::unordered_set (*)(std::string_view, std::string_view, + std::string_view, std::vector); +using func_get_input_files = void (*)(data_transfer &); // An abstract class that defines the creation of generator classes and is also a generalization class base_generator : public gninterface::interface_generator { @@ -56,16 +100,18 @@ class base_generator : public gninterface::interface_generator { ~base_generator() = default; public: - void set_const_data(std::vector &ccmp, bwargs global_external_args) { - ccmp_p = std::shared_ptr>( - (std::vector *)&ccmp, - [](const std::vector *) {}); - global_external_args_p = std::shared_ptr((bwargs *)&global_external_args, [](const bwargs *) {}); + void set_use_build_graph_depends() { + use_build_graph_depends = 1; + } + + bool has_build_graph_depends() { + return use_build_graph_depends; } public: - static inline base_generator *createGeneratorInt(func_generator, func_get_files_input); - static inline base_generator *createGeneratorLua(std::string); + static inline base_generator *create_generator_int(func_generator, func_build_graph_depends_file, + func_get_input_files); + static inline base_generator *create_generator_lua(std::string); public: static bool is_exist(base_generator *generator) { @@ -74,38 +120,39 @@ class base_generator : public gninterface::interface_generator { return 1; } - protected: - std::shared_ptr> ccmp_p; - std::shared_ptr global_external_args_p; + private: + bool use_build_graph_depends{0}; }; // The class defines the API for internal generators, i.e. built into bweas as basic class integral_generator : public base_generator { - friend base_generator *base_generator::createGeneratorInt(func_generator, func_get_files_input); + friend base_generator *base_generator::create_generator_int(func_generator, func_build_graph_depends_file, + func_get_input_files); private: - integral_generator(func_generator, func_get_files_input); + integral_generator(func_generator, func_build_graph_depends_file, func_get_input_files); ~integral_generator() = default; public: void init() override final; - void deleteGenerator() override final; - std::map> input_files(const var::struct_sb::target_out &, - const bwqueue_templates &, std::string) override final; - std::map gen_commands(const var::struct_sb::target_out &, bwqueue_templates &, - std::string, - std::map>) override final; + void _delete() override final; + std::unordered_set build_graph_depends_file(std::string_view language, std::string_view name_file, + std::string_view work_directory, + std::vector include_paths) override final; + void get_input_files(data_transfer &data_t) override final; + gen_command generate_command(data_transfer &data_t) override final; private: static inline bool init_glob_gnint{0}; func_generator generator_p; - func_get_files_input files_input_p; + func_build_graph_depends_file build_graph_depends_file_p; + func_get_input_files get_input_files_p; }; // The class defines the API for generators written in lua and presented in bweas packages class lua_generator : public base_generator { - friend base_generator *base_generator::createGeneratorLua(std::string); + friend base_generator *base_generator::create_generator_lua(std::string); private: lua_generator(std::string); @@ -113,12 +160,12 @@ class lua_generator : public base_generator { public: void init() override final; - void deleteGenerator() override final; - std::map> input_files(const var::struct_sb::target_out &, - const bwqueue_templates &, std::string) override final; - std::map gen_commands(const var::struct_sb::target_out &, bwqueue_templates &, - std::string, - std::map>) override final; + void _delete() override final; + std::unordered_set build_graph_depends_file(std::string_view language, std::string_view name_file, + std::string_view work_directory, + std::vector include_paths) override final; + void get_input_files(data_transfer &data_t) override final; + gen_command generate_command(data_transfer &data_t) override final; private: static inline bool init_glob_gnlua{0}; @@ -126,14 +173,16 @@ class lua_generator : public base_generator { bwlua::lua lua; }; -base_generator *base_generator::createGeneratorInt(func_generator generator, func_get_files_input files_input) { - return (base_generator *)new integral_generator(generator, files_input); +base_generator *base_generator::create_generator_int(func_generator generator, + func_build_graph_depends_file build_graph_depends_file, + func_get_input_files get_input_files) { + return (base_generator *)new integral_generator(generator, build_graph_depends_file, get_input_files); } -base_generator *base_generator::createGeneratorLua(std::string src_lua) { +base_generator *base_generator::create_generator_lua(std::string src_lua) { return (base_generator *)new lua_generator(src_lua); } } // namespace generator_api } // namespace bweas -#endif \ No newline at end of file +#endif diff --git a/src/bs/bwgenerator_integral.cpp b/src/bs/bwgenerator_integral.cpp index f17408c..dae1a71 100644 --- a/src/bs/bwgenerator_integral.cpp +++ b/src/bs/bwgenerator_integral.cpp @@ -1,5 +1,11 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #include "bwgenerator_integral.hpp" -#include "bwgenerator_api.hpp" #include "bwgntools.hpp" #include "tools/bwfile.hpp" @@ -8,7 +14,9 @@ using namespace generator_api; using namespace generator; using namespace bweas::bwexception; -integral_generator::integral_generator(func_generator _generator_p, func_get_files_input _files_input_p) { +integral_generator::integral_generator(func_generator _generator_p, + func_build_graph_depends_file _build_graph_depends_file_p, + func_get_input_files _get_input_files_p) { if (!init_glob_gnint) { assist.add_err("BWS-GNRT000", "Unable to parse basic arguments"); assist.add_err("BWS-GNRT001", "Internal global argument not found"); @@ -16,277 +24,42 @@ integral_generator::integral_generator(func_generator _generator_p, func_get_fil init_glob_gnint = 1; } generator_p = _generator_p; - files_input_p = _files_input_p; + build_graph_depends_file_p = _build_graph_depends_file_p; + get_input_files_p = _get_input_files_p; } void integral_generator::init() { } -void integral_generator::deleteGenerator() { +void integral_generator::_delete() { delete this; } -std::map> integral_generator::input_files(const var::struct_sb::target_out &trg, - const bwqueue_templates &templates, - std::string dir_work_endv) { - return files_input_p(trg, templates, *ccmp_p, dir_work_endv); -} -std::map integral_generator::gen_commands( - const var::struct_sb::target_out &trg, bwqueue_templates &templates, std::string dir_work_endv, - std::map> files_input) { - generator::tools::parse_basic_args(trg, templates, *global_external_args_p); - return generator_p(trg, templates, *ccmp_p, files_input, dir_work_endv); +std::unordered_set integral_generator::build_graph_depends_file(std::string_view language, + std::string_view name_file, + std::string_view work_directory, + std::vector include_paths) { + return build_graph_depends_file_p(language, name_file, work_directory, include_paths); } -std::map> bweas::generator::bwfile_inputs( - const var::struct_sb::target_out &target, const bwqueue_templates &target_queue_templates, - const std::vector &ccmp_p, std::string dir_work_endv) { - std::map> input_files; - u32t count_uses_input_files = 0; - - for (const auto &template_tmp : target_queue_templates) { - const auto &call_component_tmp = - std::find_if(ccmp_p.begin(), ccmp_p.end(), [template_tmp](const var::struct_sb::call_component &ccmp_tmp) { - return ccmp_tmp.name == template_tmp.name_call_component; - }); - - for (const auto &arg : template_tmp.args) { - var::struct_sb::template_command::arg current_arg = arg; - if (current_arg.arg_t == var::struct_sb::template_command::arg::type::trgfield && - current_arg.str_arg.find(NAME_FIELD_PROJECT_SRC_FILES) == 0) { - std::string mask; - u32t it_str = current_arg.str_arg.find(":"); - if (it_str != current_arg.str_arg.npos) { - mask = current_arg.str_arg; - mask.erase(0, it_str + 1); - } - - if (std::atoll(mask.c_str()) != 0) { - if (std::atoll(mask.c_str()) == 1) { - while (count_uses_input_files < target.prj.src_files.size()) { - if (std::filesystem::last_write_time(target.prj.src_files[count_uses_input_files]) > - std::filesystem::last_write_time(tools::get_name_output_file( - call_component_tmp->pattern_ret_files, count_uses_input_files, dir_work_endv))) - input_files[template_tmp.name].push_back(target.prj.src_files[count_uses_input_files]); - ++count_uses_input_files; - } - } - else { - for (u32t k = 0; k < target.prj.src_files.size() && k < std::atoll(mask.c_str()); - ++k, ++count_uses_input_files) { - if (std::filesystem::last_write_time(target.prj.src_files[k]) > - std::filesystem::last_write_time(tools::get_name_output_file( - call_component_tmp->pattern_ret_files, k, dir_work_endv))) - input_files[template_tmp.name].push_back(target.prj.src_files[k]); - } - } - } - current_arg.str_arg = ""; - - std::vector slc_files = bwfile::file_slc_mask(mask, target.prj.src_files); - for (u32t i = 0; i < slc_files.size(); ++i) { - if (std::filesystem::last_write_time(slc_files[i]) > - std::filesystem::last_write_time( - tools::get_name_output_file(call_component_tmp->pattern_ret_files, i, dir_work_endv))) - input_files[template_tmp.name].push_back(slc_files[i]); - ++count_uses_input_files; - } - } - else if (arg.arg_t == var::struct_sb::template_command::arg::type::features && - arg.str_arg.find(FEATURE_FIELD_BS_CURRENT_IF) == 0) { - while (count_uses_input_files < target.prj.src_files.size()) { - if (!std::filesystem::exists(tools::get_name_output_file(call_component_tmp->pattern_ret_files, - count_uses_input_files, dir_work_endv)) || - std::filesystem::last_write_time(target.prj.src_files[count_uses_input_files]) > - std::filesystem::last_write_time(tools::get_name_output_file( - call_component_tmp->pattern_ret_files, count_uses_input_files, dir_work_endv))) - input_files[template_tmp.name].push_back(target.prj.src_files[count_uses_input_files]); - ++count_uses_input_files; - } - } - } - } - - return input_files; +void integral_generator::get_input_files(data_transfer &data_t) { + get_input_files_p(data_t); } -std::map bweas::generator::bwgenerator( - const var::struct_sb::target_out &trg, bwqueue_templates &templates, - const std::vector &ccmp_p, - std::map> input_files, std::string dir_work_endv) { - std::map cmd_s; - command current_cmd; - - std::map> global_internal_args; - - std::string input_file, output_file; - - u32t used_input_files = 0; - u32t used_input_files_in_curr_template = 0; - u32t used_output_files = 0; - - bool generate_single_input = 0; - bool is_ind_template = 0; - - while (templates.size() || generate_single_input) { - auto ¤t_template = templates[0]; - const auto ¤t_ccmp = std::find_if(ccmp_p.begin(), ccmp_p.end(), - [current_template](const var::struct_sb::call_component &ccmp_tmp) { - return ccmp_tmp.name == current_template.name_call_component; - }); - generate: - if (used_input_files < input_files[current_template.name].size()) { - u32t ind_file = 0; - for (; ind_file < trg.prj.src_files.size(); ++ind_file) - if (input_files[current_template.name][used_input_files] == trg.prj.src_files[ind_file]) - break; - input_file = input_files[current_template.name][used_input_files]; - output_file = tools::get_name_output_file(current_ccmp->pattern_ret_files, ind_file, dir_work_endv); - ++used_input_files; - is_ind_template = 1; - } - else if (current_template.returnable == var::struct_sb::target_t_str(trg.target_t)) { - output_file = tools::get_name_output_file(current_ccmp->pattern_ret_files, - used_input_files_in_curr_template++, dir_work_endv); - if (!std::filesystem::exists(output_file) || used_input_files) - is_ind_template = 1; - } - else { - for (; used_output_files < trg.prj.src_files.size(); ++used_output_files) { - if (input_files[current_template.name].size() == 0) - goto init_ofile; - for (u32t i = 0; i < input_files[current_template.name].size(); ++i) - if (input_files[current_template.name][i] != trg.prj.src_files[used_output_files]) - goto init_ofile; - } - init_ofile: - output_file = - tools::get_name_output_file(current_ccmp->pattern_ret_files, used_output_files, dir_work_endv); - ++used_output_files; - } - current_cmd = current_ccmp->name_program + " "; - - for (auto arg : current_template.args) { - if (arg.arg_t == var::struct_sb::template_command::arg::type::internal) { - const auto ¤t_internal_args = global_internal_args.find(arg.str_arg); - if (current_internal_args == global_internal_args.end()) - throw bwgenerator_excp("Parameter in the template(" + current_template.name + ") - " + arg.str_arg, - "001"); - arg.str_arg = ""; - for (const std::string &file : current_internal_args->second) - arg.str_arg += file + " "; - } - else if (arg.arg_t != var::struct_sb::template_command::arg::type::string) { - if (arg.str_arg == FEATURE_FIELD_BS_CURRENT_IF) { - arg.str_arg = input_file; - ++used_input_files_in_curr_template; - generate_single_input = 1; - } - else if (arg.str_arg.find(FEATURE_FIELD_BS_CURRENT_OF) == 0) { - size_t attr_it = arg.str_arg.find(":"); - if (attr_it == arg.str_arg.npos) { - arg.str_arg = ""; - for (u32t i = 0; i < used_input_files_in_curr_template; ++i) { - std::string name_file = - tools::get_name_output_file(current_ccmp->pattern_ret_files, i, dir_work_endv); - arg.str_arg += name_file + " "; - global_internal_args[current_template.returnable].push_back(name_file); - } - } - else { - std::string attribute = arg.str_arg; - attribute.erase(0, attr_it + 1); - size_t val_attr = std::atoll(attribute.c_str()); - if (val_attr != 0) { - if (val_attr == 1) { - arg.str_arg = output_file; - global_internal_args[current_template.returnable].push_back(arg.str_arg); - } - else { - arg.str_arg = ""; - for (u32t i = 0; i < val_attr && i < input_files.size(); ++i) { - std::string name_file = - tools::get_name_output_file(current_ccmp->pattern_ret_files, i, dir_work_endv); - arg.str_arg += name_file + " "; - global_internal_args[current_template.returnable].push_back(name_file); - } - } - } - else if (attribute == "0") - continue; - else { - std::vector files = - bwfile::file_slc_mask(attribute, input_files[current_template.name]); - arg.str_arg = ""; - for (const auto &file : files) { - arg.str_arg += file + " "; - global_internal_args[current_template.returnable].push_back(file); - } - } - } - } - else if (arg.str_arg.find(NAME_FIELD_PROJECT_SRC_FILES) == 0) { - size_t attr_it = arg.str_arg.find(":"); - if (attr_it == arg.str_arg.npos) { - arg.str_arg = ""; - for (u32t i = 0; i < trg.prj.src_files.size(); ++i) { - arg.str_arg += trg.prj.src_files[i] + " "; - global_internal_args[current_template.returnable].push_back(trg.prj.src_files[i]); - } - } - else { - std::string attribute = arg.str_arg; - attribute.erase(0, attr_it + 1); - size_t val_attr = std::atoll(attribute.c_str()); - if (val_attr != 0) { - if (val_attr == 1) { - arg.str_arg = trg.prj.src_files[used_input_files]; - global_internal_args[current_template.returnable].push_back(arg.str_arg); - } - else { - arg.str_arg = ""; - for (u32t i = 0; i < val_attr && i < trg.prj.src_files.size(); ++i) { - arg.str_arg += trg.prj.src_files[i] + " "; - global_internal_args[current_template.returnable].push_back(trg.prj.src_files[i]); - } - } - } - else if (attribute == "0") - continue; - else { - std::vector files = bwfile::file_slc_mask(attribute, trg.prj.src_files); - arg.str_arg = ""; - for (const auto &file : files) { - arg.str_arg += file + " "; - global_internal_args[current_template.returnable].push_back(file); - } - } - } - } - else - throw bwgenerator_excp("Parameter in the template(" + current_template.name + ") - " + arg.str_arg, - "002"); - } - current_cmd += arg.str_arg + " "; - } - assist.next_output_important(); - assist << "GENERATED COMMAND: " + current_cmd; +gen_command integral_generator::generate_command(data_transfer &data_t) { + generator::tools::parse_basic_args(*data_t.trg, *data_t.trg_templates, *data_t.global_extern_args); + return generator_p(data_t); +} - if (is_ind_template) - cmd_s.emplace(output_file, current_cmd); - current_cmd.clear(); +std::unordered_set bweas::generator::bwbuild_graph_depends_file(std::string_view language, + std::string_view name_file, + std::string_view work_directory, + std::vector include_paths) { + return {}; +} - if (!generate_single_input || used_input_files_in_curr_template == trg.prj.src_files.size()) { - generate_single_input = 0; - used_input_files_in_curr_template = 0; - templates.erase(templates.begin()); - } - else { - input_file = ""; - output_file = ""; - is_ind_template = 0; - goto generate; - } - } +void bweas::generator::bwget_input_files(data_transfer &data_t) { +} - return cmd_s; -} \ No newline at end of file +gen_command bweas::generator::bwgenerator(data_transfer &data_t) { + return std::map{{"test", "none"}}; +} diff --git a/src/bs/bwgenerator_integral.hpp b/src/bs/bwgenerator_integral.hpp index b536f1d..eaedc7d 100644 --- a/src/bs/bwgenerator_integral.hpp +++ b/src/bs/bwgenerator_integral.hpp @@ -1,22 +1,28 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef BWGENERATOR_INTEGRAL__H #define BWGENERATOR_INTEGRAL__H -#include "bw_defs.hpp" #include +#include "bw_defs.hpp" +#include "bwgenerator_api.hpp" + namespace bweas { namespace generator { -extern std::map> bwfile_inputs( - const var::struct_sb::target_out &target, const bwqueue_templates &target_queue_templates, - const std::vector &ccmp_p, std::string dir_work_endv); +extern std::unordered_set bwbuild_graph_depends_file(std::string_view, std::string_view, std::string_view, + std::vector); + +extern void bwget_input_files(bweas::generator_api::data_transfer &); // First and basic template-based command generator -extern std::map bwgenerator(const var::struct_sb::target_out &trg, - bwqueue_templates &templates, - const std::vector &ccmp_p, - std::map> files_input, - std::string dir_work_endv); +extern bweas::generator_api::gen_command bwgenerator(bweas::generator_api::data_transfer &); } // namespace generator } // namespace bweas -#endif \ No newline at end of file +#endif diff --git a/src/bs/bwgenerator_lua.cpp b/src/bs/bwgenerator_lua.cpp index 1d58f6a..83b9f14 100644 --- a/src/bs/bwgenerator_lua.cpp +++ b/src/bs/bwgenerator_lua.cpp @@ -1,6 +1,13 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #include "bwgenerator_api.hpp" #include "bwgntools.hpp" -#include "bwluatoolslang.hpp" +#include "bwluatools.hpp" using namespace bweas; using namespace generator_api; @@ -29,59 +36,69 @@ lua_generator::lua_generator(std::string src_lua) { void lua_generator::init() { if (!lua.is_created()) throw bwgenerator_excp("", "001"); - else if (!lua.is_function(NAME_FUNCTION_GENLUA)) + else if (!lua.is_function(NAME_FUNCTION_GENERATE_COMMAND_LUA)) throw bwgenerator_excp("", "003"); - else if (!lua.is_function(NAME_FUNCTION_FILECLUA)) + else if (!lua.is_function(NAME_FUNCTION_GET_INPUT_FILE_LUA)) throw bwgenerator_excp("", "004"); - bwlua::lua::array> ccmps; - for (u32t i = 0; i < ccmp_p->size(); ++i) - ccmps.emplace_back(bwlua::lua::array{(*ccmp_p)[i].name, (*ccmp_p)[i].name_program, - (*ccmp_p)[i].pattern_ret_files}); - - lua["get_name_output_file_lua"] << lua_tools::get_name_output_file_lua; - lua["file_slc_mask"] << lua_tools::file_slc_mask_lua; - - lua["CCMPS"] = ccmps; + lua["get_name_output_file_lua"] << bwluatools::get_name_output_file_lua; + lua["file_slc_mask"] << bwluatools::file_slc_mask_lua; } -void lua_generator::deleteGenerator() { +void lua_generator::_delete() { delete this; } -std::map> lua_generator::input_files( - const var::struct_sb::target_out &target, const bwqueue_templates &target_queue_templates, - std::string dir_work_endv) { - bwlua::lua::array> tcmd_s_vec; - for (u32t i = 0; i < target_queue_templates.size(); ++i) - tcmd_s_vec.emplace_back(lua_tools::conv_to_table(target_queue_templates[i])); +std::unordered_set lua_generator::build_graph_depends_file(std::string_view language, + std::string_view name_file, + std::string_view work_directory, + std::vector include_path) { + try { + bwluatools::array dependencies = lua.call_function( + NAME_FUNCTION_BUILD_DEPENDS_LUA, language, name_file, work_directory, include_path); + return std::unordered_set{dependencies.begin(), dependencies.end()}; + } + catch (std::exception &what) { + throw bwgenerator_excp(what.what(), "005"); + } +} + +void lua_generator::get_input_files(data_transfer &data_t) { + bwluatools::array> ccmps; + for (u32t i = 0; i < (*data_t.ccmp_s).size(); ++i) + ccmps.emplace_back(bwluatools::array{(*data_t.ccmp_s)[i].name, (*data_t.ccmp_s)[i].name_program, + (*data_t.ccmp_s)[i].pattern_ret_files}); + bwluatools::array> tcmd_s_vec; + for (u32t i = 0; i < (*data_t.trg_templates).size(); ++i) + tcmd_s_vec.emplace_back(bwluatools::conv_to_table((*data_t.trg_templates)[i])); try { - return bwlua::lua::to_map(lua.call_function DEFINITION_FUNCTION_FILECLUA( - NAME_FUNCTION_FILECLUA, lua_tools::conv_to_table(target), tcmd_s_vec)); + lua["CCMPS"] = ccmps; + data_t.ifiles = bwlua::lua::to_map(lua.call_function( + NAME_FUNCTION_GET_INPUT_FILE_LUA, bwluatools::conv_to_table(*data_t.trg), tcmd_s_vec, + bwluatools::conv_to_table(data_t.dfiles))); } catch (std::exception &what) { throw bwgenerator_excp(what.what(), "005"); } } -std::map lua_generator::gen_commands( - const var::struct_sb::target_out &trg, bwqueue_templates &templates, std::string dir_work_endv, - std::map> files_input) { +gen_command lua_generator::generate_command(data_transfer &data_t) { - generator::tools::parse_basic_args(trg, templates, *global_external_args_p); + generator::tools::parse_basic_args(*data_t.trg, *data_t.trg_templates, *data_t.global_extern_args); - std::vector> tcmd_s_vec; - for (u32t i = 0; i < templates.size(); ++i) - tcmd_s_vec.emplace_back(lua_tools::conv_to_table(templates[i])); + std::vector> tcmd_s_vec; + for (u32t i = 0; i < (*data_t.trg_templates).size(); ++i) + tcmd_s_vec.emplace_back(bwluatools::conv_to_table((*data_t.trg_templates)[i])); - lua["CURRENT_TARGET"] = lua_tools::conv_to_table(trg); + lua["CURRENT_TARGET"] = bwluatools::conv_to_table(*data_t.trg); lua["CURRENT_QUEUE_TEMPLATES"] = tcmd_s_vec; - lua["CURRENT_DIR"] = dir_work_endv; + lua["CURRENT_DIR"] = data_t.work_directory; try { - return lua.call_function DEFINITION_FUNCTION_GENLUA(NAME_FUNCTION_GENLUA, bwlua::lua::to_table(files_input)); + return bwlua::lua::to_map(lua.call_function( + NAME_FUNCTION_GENERATE_COMMAND_LUA, bwlua::lua::to_table(data_t.ifiles))); } catch (std::exception &what) { throw bwgenerator_excp(what.what(), "004"); } -} \ No newline at end of file +} diff --git a/src/bs/bwgntools.cpp b/src/bs/bwgntools.cpp index cc879df..6e36e84 100644 --- a/src/bs/bwgntools.cpp +++ b/src/bs/bwgntools.cpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #include "bwgntools.hpp" using namespace bweas; @@ -58,7 +65,7 @@ void generator::tools::parse_basic_args(const var::struct_sb::target_out &target else if (current_arg.str_arg == NAME_FIELD_PROJECT_VER) current_arg.str_arg = target.prj.version_project.get_str_version(); else if (current_arg.str_arg == NAME_FIELD_PROJECT_LANG) - current_arg.str_arg = var::struct_sb::lang_str(target.prj.lang); + current_arg.str_arg = target.prj.language; else if (current_arg.str_arg == NAME_FIELD_PROJECT_PCOMPILER) current_arg.str_arg = target.prj.path_compiler; else if (current_arg.str_arg == NAME_FIELD_PROJECT_PLINKER) @@ -85,4 +92,4 @@ void generator::tools::parse_basic_args(const var::struct_sb::target_out &target current_arg.arg_t = var::struct_sb::template_command::arg::type::string; } } -} \ No newline at end of file +} diff --git a/src/bs/bwgntools.hpp b/src/bs/bwgntools.hpp index 4fca1ea..afa77d4 100644 --- a/src/bs/bwgntools.hpp +++ b/src/bs/bwgntools.hpp @@ -1,10 +1,17 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef BWGNTOOLS__H #define BWGNTOOLS__H -#include "bw_defs.hpp" - #include +#include "bw_defs.hpp" + namespace bweas { namespace generator { @@ -25,4 +32,4 @@ extern void parse_basic_args(const var::struct_sb::target_out &target, bwqueue_t } // namespace generator } // namespace bweas -#endif \ No newline at end of file +#endif diff --git a/src/bs/bwlang.hpp b/src/bs/bwlang.hpp index baafbb8..ac9beee 100644 --- a/src/bs/bwlang.hpp +++ b/src/bs/bwlang.hpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef BWLANG__H #define BWLANG__H @@ -30,6 +37,9 @@ class bwlang { // Loads external functions (passed into this function) into the interpreter (semantic analyzer) inline void load_external_tfuncs(const semantic_an::table_func &tfuncs); + // Sets custom extension fields for projects + inline void set_custom_ext_fields_project(std::map &custom_ext_fields); + template inline bool create_global_var(std::string name_var, T val = {}) { return interpreter.get_current_scope().try_create_var(name_var, val); } @@ -75,7 +85,7 @@ void bwlang::set_bwstd_funcs() { interpreter.set_std_function( "project", sl_func::project, - {param_type::FUTURE_VAR_ID, param_type::LNUM_OR_ID_VAR, param_type::LSTR_OR_ID_VAR, param_type::NEXT_TOO}); + {param_type::FUTURE_VAR_ID, param_type::LSTR_OR_ID_VAR, param_type::LSTR_OR_ID_VAR, param_type::NEXT_TOO}); interpreter.set_std_function("executable", sl_func::executable, {param_type::FUTURE_VAR_ID, param_type::LNUM_OR_ID_VAR, param_type::VAR_STRUCT_ID}); @@ -101,7 +111,7 @@ void bwlang::set_bwstd_funcs() { {param_type::VAR_STRUCT_ID, param_type::LNUM_OR_ID_VAR}); interpreter.set_std_function("standart_cpp", sl_func::standart_cpp, {param_type::VAR_STRUCT_ID, param_type::LNUM_OR_ID_VAR}); - interpreter.set_std_function("lang", sl_func::lang, {param_type::VAR_STRUCT_ID, param_type::LNUM_OR_ID_VAR}); + interpreter.set_std_function("lang", sl_func::lang, {param_type::VAR_STRUCT_ID, param_type::LSTR_OR_ID_VAR}); interpreter.set_std_function("generator", sl_func::generator, {param_type::VAR_STRUCT_ID, param_type::LSTR_OR_ID_VAR}); @@ -132,6 +142,9 @@ void bwlang::execute() { void bwlang::load_external_tfuncs(const semantic_an::table_func &tfuncs) { interpreter.load_external_func(tfuncs); } +void bwlang::set_custom_ext_fields_project(std::map &custom_ext_fields) { + var::struct_sb::project::preset_ext_fields.merge(custom_ext_fields); +} std::vector bwlang::get_targets() { std::vector targets = interpreter.export_targets(); @@ -195,4 +208,4 @@ template std::vector> &bwlang::get_class_ } // namespace bweas -#endif \ No newline at end of file +#endif diff --git a/src/bs/bwluatoolslang.hpp b/src/bs/bwluatools.cpp similarity index 70% rename from src/bs/bwluatoolslang.hpp rename to src/bs/bwluatools.cpp index 0b27841..a08f6f4 100644 --- a/src/bs/bwluatoolslang.hpp +++ b/src/bs/bwluatools.cpp @@ -1,225 +1,225 @@ -#ifndef BWLUATOOLSLANG__H -#define BWLUATOOLSLANG__H - -#include "bwgntools.hpp" -#include "lang/static_struct.hpp" -#include "tools/bwfile.hpp" -#include "tools/bwlua.hpp" - -namespace bweas { - -namespace lua_tools { - -static inline bwlua::lua::table conv_to_table(const var::struct_sb::project &prj) { - return bwlua::lua::table{ - {PRJ_VAR_NAME, prj.name_project}, - {PRJ_VAR_NAME_VER, prj.version_project.get_str_version()}, - {PRJ_VAR_NAME_LANG, lang_str(prj.lang)}, - {PRJ_VAR_NAME_PTH_C, prj.path_compiler}, - {PRJ_VAR_NAME_PTH_L, prj.path_linker}, - {PRJ_VAR_NAME_RFLAGS_C, prj.rflags_compiler}, - {PRJ_VAR_NAME_RFLAGS_L, prj.rflags_linker}, - {PRJ_VAR_NAME_DFLAGS_C, prj.dflags_compiler}, - {PRJ_VAR_NAME_DFLAGS_L, prj.dflags_linker}, - {PRJ_VAR_NAME_STD_C, prj.standart_c}, - {PRJ_VAR_NAME_STD_CPP, prj.standart_cpp}, - {PRJ_VAR_NAME_UITTEMPLATES, (bwlua::lua::integer)prj.use_it_templates}, - {PRJ_VAR_NAME_SRC_FILES, prj.src_files}, - {PRJ_VAR_NAME_UTEMPLATES, prj.vec_templates}}; -} - -static inline bwlua::lua::array conv_to_table( - const std::vector &args) { - bwlua::lua::array vec_args; - for (const auto &arg : args) - vec_args.emplace_back( - bwlua::lua::keyValue{arg.str_arg, (bwlua::lua::integer)arg.arg_t}); - return vec_args; -} - -static inline bwlua::lua::table conv_to_table(const var::struct_sb::template_command &tmp_c) { - return bwlua::lua::table{ - {NAME_FIELD_TEMPLATE_COMMAND_NAME, tmp_c.name}, - {NAME_FIELD_TEMPLATE_COMMAND_NAME_CCMP, tmp_c.name_call_component}, - {NAME_FIELD_TEMPLATE_COMMAND_NAME_ACCEPTS_ARGS, tmp_c.name_accept_params}, - {NAME_FIELD_TEMPLATE_COMMAND_NAME_ARGS, conv_to_table(tmp_c.args)}, - {NAME_FIELD_TEMPLATE_COMMAND_RET, tmp_c.returnable}}; -} - -static inline bwlua::lua::table conv_to_table(const var::struct_sb::call_component &ccmp) { - return bwlua::lua::table{{NAME_FIELD_CALL_COMPONENT_NAME, ccmp.name}, - {NAME_FIELD_CALL_COMPONENT_NAME_PROGRAM, ccmp.name_program}, - {NAME_FIELD_CALL_COMPONENT_PATTERN_FILES, ccmp.pattern_ret_files}}; -} - -static inline bwlua::lua::table conv_to_table(const var::struct_sb::target &trg_o) { - return bwlua::lua::table{{TRG_NAME_FIELD_PROJECT, conv_to_table(*trg_o.prj)}, - {TRG_VAR_NAME_TYPE_T, target_t_str(trg_o.target_t)}, - {TRG_VAR_NAME_CFG, cfg_str(trg_o.target_cfg)}, - {TRG_NAME_FIELD_NTARGET, trg_o.name_target}, - {TRG_VAR_NAME_VER, trg_o.version_target.get_str_version()}, - {TRG_VAR_NAME_LLIBS, trg_o.target_vec_libs}}; -} - -static inline bwlua::lua::table conv_to_table(const var::struct_sb::target_out &trg_o) { - return bwlua::lua::table{{TRG_NAME_FIELD_PROJECT, conv_to_table(trg_o.prj)}, - {TRG_VAR_NAME_TYPE_T, target_t_str(trg_o.target_t)}, - {TRG_VAR_NAME_CFG, cfg_str(trg_o.target_cfg)}, - {TRG_NAME_FIELD_NTARGET, trg_o.name_target}, - {TRG_VAR_NAME_VER, trg_o.version_target.get_str_version()}, - {TRG_VAR_NAME_LLIBS, trg_o.target_vec_libs}}; -} - -static inline var::struct_sb::project conv_to_project(bwlua::lua::table prj_t) { - var::struct_sb::project prj; - - prj.name_project = std::any_cast(prj_t[PRJ_VAR_NAME]); - prj.version_project = std::any_cast(prj_t[PRJ_VAR_NAME_VER]); - prj.lang = var::struct_sb::to_lang(std::any_cast(prj_t[PRJ_VAR_NAME_LANG])); - prj.path_compiler = std::any_cast(prj_t[PRJ_VAR_NAME_PTH_C]); - prj.path_linker = std::any_cast(prj_t[PRJ_VAR_NAME_PTH_L]); - prj.rflags_compiler = std::any_cast(prj_t[PRJ_VAR_NAME_RFLAGS_C]); - prj.rflags_linker = std::any_cast(prj_t[PRJ_VAR_NAME_RFLAGS_L]); - prj.dflags_compiler = std::any_cast(prj_t[PRJ_VAR_NAME_DFLAGS_C]); - prj.dflags_linker = std::any_cast(prj_t[PRJ_VAR_NAME_DFLAGS_L]); - prj.standart_c = std::any_cast(prj_t[PRJ_VAR_NAME_STD_C]); - prj.standart_cpp = std::any_cast(prj_t[PRJ_VAR_NAME_STD_CPP]); - prj.use_it_templates = std::any_cast(prj_t[PRJ_VAR_NAME_UITTEMPLATES]); - prj.src_files = std::any_cast>(prj_t[PRJ_VAR_NAME_SRC_FILES]); - prj.vec_templates = std::any_cast>(prj_t[PRJ_VAR_NAME_UTEMPLATES]); - - return prj; -} - -static inline var::struct_sb::target_out conv_to_target(bwlua::lua::table &trg_o_t) { - var::struct_sb::target_out trg; - - trg.prj = conv_to_project(std::any_cast>(trg_o_t[TRG_NAME_FIELD_PROJECT])); - trg.target_t = var::struct_sb::to_type_target(std::any_cast(trg_o_t[TRG_VAR_NAME_TYPE_T])); - trg.target_cfg = var::struct_sb::to_cfg(std::any_cast(trg_o_t[TRG_VAR_NAME_CFG])); - trg.name_target = std::any_cast(trg_o_t[TRG_NAME_FIELD_NTARGET]); - trg.version_target = std::any_cast(trg_o_t[TRG_VAR_NAME_VER]); - trg.target_vec_libs = std::any_cast>(trg_o_t[TRG_VAR_NAME_LLIBS]); - - return trg; -} - -static inline std::vector conv_to_args( - bwlua::lua::array> args) { - std::vector _args; - - for (const auto &arg : args) - _args.emplace_back(std::any_cast(arg[0]), - std::any_cast(arg[1])); - - return _args; -} - -static inline var::struct_sb::template_command conv_to_template(bwlua::lua::table &tcmd) { - var::struct_sb::template_command _tcmd; - - _tcmd.name = std::any_cast(tcmd[NAME_FIELD_CALL_COMPONENT_NAME]); - _tcmd.name_call_component = std::any_cast(tcmd[NAME_FIELD_TEMPLATE_COMMAND_NAME_CCMP]); - _tcmd.name_accept_params = - std::any_cast>(tcmd[NAME_FIELD_TEMPLATE_COMMAND_NAME_ACCEPTS_ARGS]); - _tcmd.args = conv_to_args( - std::any_cast>>(tcmd[NAME_FIELD_TEMPLATE_COMMAND_NAME_ARGS])); - _tcmd.returnable = std::any_cast(tcmd[NAME_FIELD_TEMPLATE_COMMAND_RET]); - - return _tcmd; -} - -static inline var::struct_sb::call_component conv_to_call_components(bwlua::lua::table &ccmp) { - var::struct_sb::call_component _ccmp; - - _ccmp.name = std::any_cast(ccmp[NAME_FIELD_CALL_COMPONENT_NAME]); - _ccmp.name_program = std::any_cast(ccmp[NAME_FIELD_CALL_COMPONENT_NAME_PROGRAM]); - _ccmp.pattern_ret_files = std::any_cast(ccmp[NAME_FIELD_CALL_COMPONENT_PATTERN_FILES]); - - return _ccmp; -} - -static inline int get_var(lua_State *L) { - std::string name_var = bwlua::tools::pop_stack(L); - bwlua::lua::integer var_t = bwlua::tools::pop_stack(L); - var::scope *ref = (var::scope *)bwlua::tools::pop_stack(L); - try { - if (var_t == 1) - bwlua::tools::push_stack(L, (bwlua::lua::integer)ref->get_var_value(name_var)); - else if (var_t == 2) - bwlua::tools::push_stack(L, ref->get_var_value(name_var)); - else if (var_t == 3) - bwlua::tools::push_stack(L, ref->get_var_value>(name_var)); - else if (var_t == 4) - bwlua::tools::push_stack(L, ref->get_var_value>(name_var)); - else if (var_t == 5) - bwlua::tools::push_stack(L, conv_to_table(ref->get_var_value(name_var))); - else if (var_t == 6) - bwlua::tools::push_stack(L, conv_to_table(ref->get_var_value(name_var))); - else if (var_t == 7) - bwlua::tools::push_stack(L, conv_to_table(ref->get_var_value(name_var))); - else if (var_t == 8) - bwlua::tools::push_stack(L, conv_to_table(ref->get_var_value(name_var))); - else if (var_t == 9) - bwlua::tools::push_stack(L, ref->get_var_value>(name_var)); - } - catch (...) { - bwlua::tools::push_stack(L, "\"" + name_var + "\" variable was not found."); - }; - - return 1; -} - -static inline int set_var(lua_State *L) { - std::string name_var = bwlua::tools::pop_stack(L); - std::any value = bwlua::tools::pop_stack(L); - var::scope *ref = (var::scope *)bwlua::tools::pop_stack(L); - try { - if (value.type() == typeid(i32t) && !ref->try_create_var(name_var, std::any_cast(value))) - ref->get_var_value(name_var) = std::any_cast(value); - else if (value.type() == typeid(std::string) && - !ref->try_create_var(name_var, std::any_cast(value))) - ref->get_var_value(name_var) = std::any_cast(value); - else if (value.type() == typeid(std::vector)) { - std::vector any_vec = std::any_cast>(value); - auto el_tmp = std::any_cast(any_vec[0]); - if (el_tmp.type() == typeid(i32t)) { - std::vector tmp_vec; - for (const auto &it : any_vec) - tmp_vec.push_back(std::any_cast(it)); - if (!ref->try_create_var(name_var, tmp_vec)) - ref->get_var_value>(name_var) = tmp_vec; - } - else if (el_tmp.type() == typeid(std::string)) { - std::vector tmp_vec; - for (const auto &it : any_vec) - tmp_vec.push_back(std::any_cast(it)); - if (!ref->try_create_var(name_var, tmp_vec)) - ref->get_var_value>(name_var) = tmp_vec; - } - } - } - catch (...) { - } - - return 0; -} - -static inline int get_name_output_file_lua(lua_State *L) { - bwlua::tools::push_stack( - L, - generator::tools::get_name_output_file(lua_tostring(L, -3), lua_tointeger(L, -2), lua_tostring(L, -1)).c_str()); - return 1; -} -static inline int file_slc_mask_lua(lua_State *L) { - commands cmd_s = bwlua::tools::pop_stack(L); - cmd_s = bwfile::file_slc_mask(lua_tostring(L, -2), cmd_s); - bwlua::tools::push_stack(L, cmd_s); - return 1; -} - -} // namespace lua_tools - -} // namespace bweas - -#endif \ No newline at end of file +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + +#include "bwluatools.hpp" + +using namespace bweas; + +bwluatools::table bwluatools::conv_to_table(const var::struct_sb::project &prj) { + return bwlua::lua::table{ + {PRJ_VAR_NAME, prj.name_project}, + {PRJ_VAR_NAME_VER, prj.version_project.get_str_version()}, + {PRJ_VAR_NAME_LANG, prj.language}, + {PRJ_VAR_NAME_PTH_C, prj.path_compiler}, + {PRJ_VAR_NAME_PTH_L, prj.path_linker}, + {PRJ_VAR_NAME_RFLAGS_C, prj.rflags_compiler}, + {PRJ_VAR_NAME_RFLAGS_L, prj.rflags_linker}, + {PRJ_VAR_NAME_DFLAGS_C, prj.dflags_compiler}, + {PRJ_VAR_NAME_DFLAGS_L, prj.dflags_linker}, + {PRJ_VAR_NAME_STD_C, prj.standart_c}, + {PRJ_VAR_NAME_STD_CPP, prj.standart_cpp}, + {PRJ_VAR_NAME_UITTEMPLATES, (bwlua::lua::integer)prj.use_it_templates}, + {PRJ_VAR_NAME_SRC_FILES, prj.src_files}, + {PRJ_VAR_NAME_UTEMPLATES, prj.vec_templates}, + {PRJ_VAR_NAME_CUSTOM_EXT_FIELDS, prj.custom_ext_fields}}; +} + +bwluatools::array bwluatools::conv_to_table(const std::vector &args) { + array vec_args; + for (const auto &arg : args) + vec_args.emplace_back( + bwlua::lua::key_value{arg.str_arg, (bwlua::lua::integer)arg.arg_t}); + return vec_args; +} + +bwluatools::table bwluatools::conv_to_table(const var::struct_sb::template_command &tmp_c) { + return table{{NAME_FIELD_TEMPLATE_COMMAND_NAME, tmp_c.name}, + {NAME_FIELD_TEMPLATE_COMMAND_NAME_CCMP, tmp_c.name_call_component}, + {NAME_FIELD_TEMPLATE_COMMAND_NAME_ACCEPTS_ARGS, tmp_c.name_accept_params}, + {NAME_FIELD_TEMPLATE_COMMAND_NAME_ARGS, conv_to_table(tmp_c.args)}, + {NAME_FIELD_TEMPLATE_COMMAND_RET, tmp_c.returnable}}; +} + +bwluatools::table bwluatools::conv_to_table(const var::struct_sb::call_component &ccmp) { + return bwluatools::table{{NAME_FIELD_CALL_COMPONENT_NAME, ccmp.name}, + {NAME_FIELD_CALL_COMPONENT_NAME_PROGRAM, ccmp.name_program}, + {NAME_FIELD_CALL_COMPONENT_PATTERN_FILES, ccmp.pattern_ret_files}}; +} + +bwluatools::table bwluatools::conv_to_table(const var::struct_sb::target &trg_o) { + return bwluatools::table{{TRG_NAME_FIELD_PROJECT, conv_to_table(*trg_o.prj)}, + {TRG_VAR_NAME_TYPE_T, target_t_str(trg_o.target_t)}, + {TRG_VAR_NAME_CFG, cfg_str(trg_o.target_cfg)}, + {TRG_NAME_FIELD_NTARGET, trg_o.name_target}, + {TRG_VAR_NAME_VER, trg_o.version_target.get_str_version()}, + {TRG_VAR_NAME_LLIBS, trg_o.target_vec_libs}}; +} + +bwluatools::table bwluatools::conv_to_table(const var::struct_sb::target_out &trg_o) { + return bwluatools::table{{TRG_NAME_FIELD_PROJECT, conv_to_table(trg_o.prj)}, + {TRG_VAR_NAME_TYPE_T, target_t_str(trg_o.target_t)}, + {TRG_VAR_NAME_CFG, cfg_str(trg_o.target_cfg)}, + {TRG_NAME_FIELD_NTARGET, trg_o.name_target}, + {TRG_VAR_NAME_VER, trg_o.version_target.get_str_version()}, + {TRG_VAR_NAME_LLIBS, trg_o.target_vec_libs}}; +} +bwluatools::table> bwluatools::conv_to_table( + const bweas::bwdepends_files::depends_map &dfiles) { + bwluatools::table> _dfiles; + for (const auto &dfile : dfiles) + _dfiles.insert({dfile.first, {dfile.second.begin(), dfile.second.end()}}); + return _dfiles; +} + +var::struct_sb::project bwluatools::conv_to_project(bwluatools::table prj_t) { + var::struct_sb::project prj; + + prj.name_project = std::any_cast(prj_t[PRJ_VAR_NAME]); + prj.version_project = std::any_cast(prj_t[PRJ_VAR_NAME_VER]); + prj.language = std::any_cast(prj_t[PRJ_VAR_NAME_LANG]); + prj.path_compiler = std::any_cast(prj_t[PRJ_VAR_NAME_PTH_C]); + prj.path_linker = std::any_cast(prj_t[PRJ_VAR_NAME_PTH_L]); + prj.rflags_compiler = std::any_cast(prj_t[PRJ_VAR_NAME_RFLAGS_C]); + prj.rflags_linker = std::any_cast(prj_t[PRJ_VAR_NAME_RFLAGS_L]); + prj.dflags_compiler = std::any_cast(prj_t[PRJ_VAR_NAME_DFLAGS_C]); + prj.dflags_linker = std::any_cast(prj_t[PRJ_VAR_NAME_DFLAGS_L]); + prj.standart_c = std::any_cast(prj_t[PRJ_VAR_NAME_STD_C]); + prj.standart_cpp = std::any_cast(prj_t[PRJ_VAR_NAME_STD_CPP]); + prj.use_it_templates = std::any_cast(prj_t[PRJ_VAR_NAME_UITTEMPLATES]); + prj.src_files = std::any_cast>(prj_t[PRJ_VAR_NAME_SRC_FILES]); + prj.vec_templates = std::any_cast>(prj_t[PRJ_VAR_NAME_UTEMPLATES]); + prj.custom_ext_fields = std::any_cast>(prj_t[PRJ_VAR_NAME_CUSTOM_EXT_FIELDS]); + + return prj; +} + +var::struct_sb::target_out bwluatools::conv_to_target(bwluatools::table &trg_o_t) { + var::struct_sb::target_out trg; + + trg.prj = conv_to_project(std::any_cast>(trg_o_t[TRG_NAME_FIELD_PROJECT])); + trg.target_t = var::struct_sb::to_type_target(std::any_cast(trg_o_t[TRG_VAR_NAME_TYPE_T])); + trg.target_cfg = var::struct_sb::to_cfg(std::any_cast(trg_o_t[TRG_VAR_NAME_CFG])); + trg.name_target = std::any_cast(trg_o_t[TRG_NAME_FIELD_NTARGET]); + trg.version_target = std::any_cast(trg_o_t[TRG_VAR_NAME_VER]); + trg.target_vec_libs = std::any_cast>(trg_o_t[TRG_VAR_NAME_LLIBS]); + + return trg; +} + +std::vector bwluatools::conv_to_args( + bwluatools::array> args) { + std::vector _args; + + for (const auto &arg : args) + _args.emplace_back(std::any_cast(arg[0]), + std::any_cast(arg[1])); + + return _args; +} + +var::struct_sb::template_command bwluatools::conv_to_template(bwluatools::table &tcmd) { + var::struct_sb::template_command _tcmd; + + _tcmd.name = std::any_cast(tcmd[NAME_FIELD_CALL_COMPONENT_NAME]); + _tcmd.name_call_component = std::any_cast(tcmd[NAME_FIELD_TEMPLATE_COMMAND_NAME_CCMP]); + _tcmd.name_accept_params = + std::any_cast>(tcmd[NAME_FIELD_TEMPLATE_COMMAND_NAME_ACCEPTS_ARGS]); + _tcmd.args = conv_to_args( + std::any_cast>>(tcmd[NAME_FIELD_TEMPLATE_COMMAND_NAME_ARGS])); + _tcmd.returnable = std::any_cast(tcmd[NAME_FIELD_TEMPLATE_COMMAND_RET]); + + return _tcmd; +} + +var::struct_sb::call_component bwluatools::conv_to_call_components(bwluatools::table &ccmp) { + var::struct_sb::call_component _ccmp; + + _ccmp.name = std::any_cast(ccmp[NAME_FIELD_CALL_COMPONENT_NAME]); + _ccmp.name_program = std::any_cast(ccmp[NAME_FIELD_CALL_COMPONENT_NAME_PROGRAM]); + _ccmp.pattern_ret_files = std::any_cast(ccmp[NAME_FIELD_CALL_COMPONENT_PATTERN_FILES]); + + return _ccmp; +} + +int bwluatools::get_var(lua_State *L) { + std::string name_var = bwlua::tools::pop_stack(L); + bwlua::lua::integer var_t = bwlua::tools::pop_stack(L); + var::scope *ref = (var::scope *)bwlua::tools::pop_stack(L); + try { + if (var_t == 1) + bwlua::tools::push_stack(L, (bwlua::lua::integer)ref->get_var_value(name_var)); + else if (var_t == 2) + bwlua::tools::push_stack(L, ref->get_var_value(name_var)); + else if (var_t == 3) + bwlua::tools::push_stack(L, ref->get_var_value>(name_var)); + else if (var_t == 4) + bwlua::tools::push_stack(L, ref->get_var_value>(name_var)); + else if (var_t == 5) + bwlua::tools::push_stack(L, conv_to_table(ref->get_var_value(name_var))); + else if (var_t == 6) + bwlua::tools::push_stack(L, conv_to_table(ref->get_var_value(name_var))); + else if (var_t == 7) + bwlua::tools::push_stack(L, conv_to_table(ref->get_var_value(name_var))); + else if (var_t == 8) + bwlua::tools::push_stack(L, conv_to_table(ref->get_var_value(name_var))); + else if (var_t == 9) + bwlua::tools::push_stack(L, ref->get_var_value>(name_var)); + } + catch (...) { + bwlua::tools::push_stack(L, "\"" + name_var + "\" variable was not found."); + }; + + return 1; +} + +int bwluatools::set_var(lua_State *L) { + std::string name_var = bwlua::tools::pop_stack(L); + std::any value = bwlua::tools::pop_stack(L); + var::scope *ref = (var::scope *)bwlua::tools::pop_stack(L); + try { + if (value.type() == typeid(i32t) && !ref->try_create_var(name_var, std::any_cast(value))) + ref->get_var_value(name_var) = std::any_cast(value); + else if (value.type() == typeid(std::string) && + !ref->try_create_var(name_var, std::any_cast(value))) + ref->get_var_value(name_var) = std::any_cast(value); + else if (value.type() == typeid(std::vector)) { + std::vector any_vec = std::any_cast>(value); + auto el_tmp = std::any_cast(any_vec[0]); + if (el_tmp.type() == typeid(i32t)) { + std::vector tmp_vec; + for (const auto &it : any_vec) + tmp_vec.push_back(std::any_cast(it)); + if (!ref->try_create_var(name_var, tmp_vec)) + ref->get_var_value>(name_var) = tmp_vec; + } + else if (el_tmp.type() == typeid(std::string)) { + std::vector tmp_vec; + for (const auto &it : any_vec) + tmp_vec.push_back(std::any_cast(it)); + if (!ref->try_create_var(name_var, tmp_vec)) + ref->get_var_value>(name_var) = tmp_vec; + } + } + } + catch (...) { + } + + return 0; +} + +int bwluatools::get_name_output_file_lua(lua_State *L) { + bwlua::tools::push_stack( + L, + generator::tools::get_name_output_file(lua_tostring(L, -3), lua_tointeger(L, -2), lua_tostring(L, -1)).c_str()); + return 1; +} +int bwluatools::file_slc_mask_lua(lua_State *L) { + commands cmd_s = bwlua::tools::pop_stack(L); + cmd_s = bwfile::file_slc_mask(lua_tostring(L, -2), cmd_s); + bwlua::tools::push_stack(L, cmd_s); + return 1; +} diff --git a/src/bs/bwluatools.hpp b/src/bs/bwluatools.hpp new file mode 100644 index 0000000..2ddb60e --- /dev/null +++ b/src/bs/bwluatools.hpp @@ -0,0 +1,71 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + +#ifndef BWLUATOOLS_H +#define BWLUATOOLS_H + +#include "bwdepends_files.hpp" +#include "bwgntools.hpp" + +#include "lang/scope.hpp" +#include "lang/static_struct.hpp" + +#include "tools/bwfile.hpp" +#include "tools/bwlua.hpp" + +namespace bweas { +class bwluatools; +} // namespace bweas + +// A class providing tools for simplified interaction between bweas and lua structures +class bweas::bwluatools { + public: + template using ref = bwlua::lua::ref; + + template using array = bwlua::lua::array; + template using key_value = bwlua::lua::key_value; + template using table = bwlua::lua::table; + + using integer = bwlua::lua::integer; + using number = bwlua::lua::number; + + using nil = bwlua::lua::nil; + + // Functions for converting standard bweas structures into appropriate containers for lua + public: + static table conv_to_table(const var::struct_sb::project &prj); + + static array conv_to_table(const std::vector &args); + static table conv_to_table(const var::struct_sb::template_command &tmp_c); + + static table conv_to_table(const var::struct_sb::call_component &ccmp); + + static table conv_to_table(const var::struct_sb::target &trg_o); + static table conv_to_table(const var::struct_sb::target_out &trg_o); + + static table> conv_to_table(const bweas::bwdepends_files::depends_map &dfiles); + + // Functions for converting containers for lua to the corresponding bweas structures + public: + static var::struct_sb::project conv_to_project(table prj_t); + + static std::vector conv_to_args(array> args); + static var::struct_sb::template_command conv_to_template(table &tcmd); + + static var::struct_sb::call_component conv_to_call_components(table &ccmp); + + static var::struct_sb::target_out conv_to_target(table &trg_o_t); + + // Auxiliary functions for lua scripts for interacting with bweas (wrappers over bweas functions) + public: + static int get_var(lua_State *L); + static int set_var(lua_State *L); + + static int get_name_output_file_lua(lua_State *L); + static int file_slc_mask_lua(lua_State *L); +}; +#endif diff --git a/src/bs/bwmodule.cpp b/src/bs/bwmodule.cpp index 3706ea9..e64e41e 100644 --- a/src/bs/bwmodule.cpp +++ b/src/bs/bwmodule.cpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #include "bwmodule.hpp" using namespace bweas; @@ -7,6 +14,8 @@ module::module_mg::module_mg() { if (!init_glob) { assist.add_err("BWS-MDL000", "Failed to load module dependent dll file"); assist.add_err("BWS-MDL001", "Failed to get the specified module function"); + + init_glob = 1; } } @@ -49,4 +58,4 @@ semantic_an::table_func module::module_mg::init_tsfunc(modules &mds) { tfuncs.insert(func_md); } return tfuncs; -} \ No newline at end of file +} diff --git a/src/bs/bwmodule.hpp b/src/bs/bwmodule.hpp index 7fe8395..fc1c962 100644 --- a/src/bs/bwmodule.hpp +++ b/src/bs/bwmodule.hpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef BWMODULE__H #define BWMODULE__H @@ -39,4 +46,4 @@ class module_mg { } // namespace module } // namespace bweas -#endif \ No newline at end of file +#endif diff --git a/src/bs/bwpackage.cpp b/src/bs/bwpackage.cpp index 7df7cb0..6ba420e 100644 --- a/src/bs/bwpackage.cpp +++ b/src/bs/bwpackage.cpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #include "bwpackage.hpp" #include "tools/bwlz4.hpp" @@ -34,6 +41,10 @@ std::string bwpackage::init(data_bw_package _data, bool is_create_pckg) { else if (!config_json.contains("bweas-version") || ((bw_version = var::struct_sb::version(config_json["bweas-version"])) == "0.0.0")) throw bwpackage_excp("Build system version field is empty", "002"); + else if (!config_json.contains("custom_fields_project") && !config_json["custom_fields_project"].is_structured()) + throw bwpackage_excp( + "Definition of custom fields for the project must be in the form of key-value (string and string)", "002"); + cfg_package.custom_ext_fields_project = config_json["custom_fields_project"]; if (config_json.contains("cache-gn")) { nlohmann::json metainf_ch = config_json["cache-gn"]; @@ -71,16 +82,22 @@ std::string bwpackage::init(data_bw_package _data, bool is_create_pckg) { "002"); else if (!metainf_gn.contains("features-generator") || !metainf_gn["features-generator"].is_array()) throw bwpackage_excp("Generator metadata should include a list of new generator features", "002"); - + else if (config_json.contains("use_custom_search_dependencies") && + !config_json["use_custom_search_dependencies"].is_boolean()) + throw bwpackage_excp( + "Definition of custom fields for the project must be in the form of key-value (string and string)", + "002"); auto it_gnlua_script = assist.open_file(metainf_gn["src-luafile-gen"]); if (is_create_pckg) { cfg_package.generators.emplace_back(generator.key(), metainf_gn["features-generator"], + metainf_gn["use_custom_search_dependencies"], assist.read_file(assist.get_ref_file(it_gnlua_script))); _data.src_lua_generators.push_back( cfg_package.generators[cfg_package.generators.size() - 1].src_lua_generator); } else { cfg_package.generators.emplace_back(generator.key(), metainf_gn["features-generator"], + metainf_gn["use_custom_search_dependencies"], _data.src_lua_generators[i]); ++i; } @@ -170,4 +187,4 @@ void bwpackage::load(std::string raw_data_package) { bool bwpackage::is_init() { return name_package.size(); -} \ No newline at end of file +} diff --git a/src/bs/bwpackage.hpp b/src/bs/bwpackage.hpp index 15d7ae8..a69bea6 100644 --- a/src/bs/bwpackage.hpp +++ b/src/bs/bwpackage.hpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef BWPACKAGE__H #define BWPACKAGE__H @@ -73,18 +80,23 @@ class bwpackage { struct generator_lua { generator_lua() = default; generator_lua(std::string _name_generator, std::vector _features_generator, - std::string _src_lua_generator) + bool _use_custom_build_graph_depends, std::string _src_lua_generator) : name_generator(_name_generator), features_generator(_features_generator), - src_lua_generator(_src_lua_generator) { + src_lua_generator(_src_lua_generator), + use_custom_build_graph_depends(_use_custom_build_graph_depends) { } std::string name_generator; std::vector features_generator; std::string src_lua_generator; + + // Use a custom file dependency(search) system + bool use_custom_build_graph_depends{0}; }; cache_lua cache; std::vector generators; module::module_mg::modules mds; + std::map custom_ext_fields_project; }; // Returns a packet compressed by the lz4 algorithm, with the signature of a bweas packet @@ -113,4 +125,4 @@ class bwpackage { }; } // namespace bweas -#endif \ No newline at end of file +#endif diff --git a/src/bs/lang/expression.hpp b/src/bs/lang/expression.hpp index f1eb2fa..ba07575 100644 --- a/src/bs/lang/expression.hpp +++ b/src/bs/lang/expression.hpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the GNU General Public License 2.0 (GPL-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef EXPRESSION__H #define EXPRESSION__H @@ -213,4 +220,4 @@ static inline token_expr::token_type conv_param_type_to_token_type(param_type _p } } // namespace aef_expr -#endif \ No newline at end of file +#endif diff --git a/src/bs/lang/interpreter.cpp b/src/bs/lang/interpreter.cpp index 1ba4c3f..add47d8 100644 --- a/src/bs/lang/interpreter.cpp +++ b/src/bs/lang/interpreter.cpp @@ -11,12 +11,10 @@ interpreter_exec::interpreter_exec() { assist.add_err("RTT003", "It is impossible to find the structure"); assist.add_err("RTT004", "Failed to open file"); assist.add_err("RTT005", "Internal function error"); + + init_glob = 1; } } -interpreter_exec::interpreter_exec(config conf) { - interpreter_exec(); - interp_conf = conf; -} void interpreter_exec::set_config(config conf) { interp_conf = conf; @@ -127,4 +125,4 @@ void interpreter_exec::load_external_func(const semantic_an::table_func &tfuncs) void interpreter_exec::set_std_function(std::string name_token_func, aef_expr::notion_func::func_t func_ref, std::vector expected_param) { smt_analyzer.add_func_flink(name_token_func, func_ref, expected_param); -} \ No newline at end of file +} diff --git a/src/bs/lang/interpreter.hpp b/src/bs/lang/interpreter.hpp index 42971b8..4bd3e2e 100644 --- a/src/bs/lang/interpreter.hpp +++ b/src/bs/lang/interpreter.hpp @@ -48,7 +48,6 @@ class interpreter_exec { public: interpreter_exec(); - interpreter_exec(config conf); interpreter_exec(interpreter_exec &&) = delete; interpreter_exec(const interpreter_exec &) = delete; @@ -94,4 +93,4 @@ class interpreter_exec { }; } // namespace interpreter -#endif \ No newline at end of file +#endif diff --git a/src/bs/lang/lexer.cpp b/src/bs/lang/lexer.cpp index 847c2cb..c857408 100644 --- a/src/bs/lang/lexer.cpp +++ b/src/bs/lang/lexer.cpp @@ -229,4 +229,4 @@ std::vector lex_an::analysis() { "000"); return tokens; -} \ No newline at end of file +} diff --git a/src/bs/lang/parser_utility.cpp b/src/bs/lang/parser_utility.cpp index 0da85ae..c9672c7 100644 --- a/src/bs/lang/parser_utility.cpp +++ b/src/bs/lang/parser_utility.cpp @@ -131,4 +131,4 @@ param_type parser::utility::type_param_in_str(std::string str) { return param_type::NEXT_TOO; else return param_type::SIZE_ENUM_PARAMS; -} \ No newline at end of file +} diff --git a/src/bs/lang/scope.hpp b/src/bs/lang/scope.hpp index 6cd569d..8a176ab 100644 --- a/src/bs/lang/scope.hpp +++ b/src/bs/lang/scope.hpp @@ -335,4 +335,4 @@ inline void scope::clear() { } // namespace var -#endif \ No newline at end of file +#endif diff --git a/src/bs/lang/semantic_an.cpp b/src/bs/lang/semantic_an.cpp index 37e33ae..5e8e0a4 100644 --- a/src/bs/lang/semantic_an.cpp +++ b/src/bs/lang/semantic_an.cpp @@ -820,4 +820,4 @@ void semantic_analyzer::defining_call_func(const std::string &name, notion_func else if (std::find(name_func_with_semantic_an.begin(), name_func_with_semantic_an.end(), name) != name_func_with_semantic_an.end()) nfunc.only_with_semantic = 1; -} \ No newline at end of file +} diff --git a/src/bs/lang/static_linking_func.cpp b/src/bs/lang/static_linking_func.cpp index 0faca2a..cded13d 100644 --- a/src/bs/lang/static_linking_func.cpp +++ b/src/bs/lang/static_linking_func.cpp @@ -9,6 +9,8 @@ using namespace aef_expr; +std::map var::struct_sb::project::preset_ext_fields; + const std::vector sl_func::name_static_func_sm = {"exp_data"}; static const std::array vec_name_config_var = { PRJ_VAR_NAME_DFLAGS_C, PRJ_VAR_NAME_DFLAGS_L, PRJ_VAR_NAME_RFLAGS_C, PRJ_VAR_NAME_RFLAGS_L, @@ -80,8 +82,8 @@ static void update_cfg_struct(const std::string &name_var, var::scope &curr_scop else if (tmp_str_postfix == PRJ_VAR_NAME_LANG) { if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 1) return; - curr_scope.get_var_value(tmp_str_prefix).lang = - (var::struct_sb::language)curr_scope.get_var_value(name_var); + curr_scope.get_var_value(tmp_str_prefix).language = + curr_scope.get_var_value(name_var); } else if (tmp_str_postfix == PRJ_VAR_NAME_VER) { if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 2) @@ -143,6 +145,14 @@ static void update_cfg_struct(const std::string &name_var, var::scope &curr_scop curr_scope.get_var_value(tmp_str_prefix).target_vec_libs = curr_scope.get_var_value>(name_var); } + else { + if (curr_scope.what_type(tmp_str_prefix) != 5 && curr_scope.what_type(name_var) != 2) + return; + auto prj = curr_scope.get_var_value(tmp_str_prefix); + auto it_field = prj.custom_ext_fields.find(tmp_str_postfix); + if (it_field != prj.custom_ext_fields.end()) + it_field->second = curr_scope.get_var_value(name_var); + } return; } } @@ -166,8 +176,8 @@ void sl_func::set(const std::vector &sub_expr, var::scope &curr_ curr_scope.get_var_value>(sub_expr[0].token_of_subexpr[0].token_val) = { std::stoi(sub_expr[1].token_of_subexpr[0].token_val.c_str())}; else if (index_var == 0) - (void)curr_scope.create_var(sub_expr[0].token_of_subexpr[0].token_val, - std::stoll(sub_expr[1].token_of_subexpr[0].token_val.c_str())); + (void)curr_scope.create_var(sub_expr[0].token_of_subexpr[0].token_val, + std::stoll(sub_expr[1].token_of_subexpr[0].token_val.c_str())); else throw semantic_an::rt_semantic_excp( parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + " Var - [" + @@ -182,8 +192,8 @@ void sl_func::set(const std::vector &sub_expr, var::scope &curr_ curr_scope.get_var_value>(sub_expr[0].token_of_subexpr[0].token_val) = { sub_expr[1].token_of_subexpr[0].token_val}; else if (index_var == 0) - (void)curr_scope.create_var(sub_expr[0].token_of_subexpr[0].token_val, - sub_expr[1].token_of_subexpr[0].token_val); + (void)curr_scope.create_var(sub_expr[0].token_of_subexpr[0].token_val, + sub_expr[1].token_of_subexpr[0].token_val); else throw semantic_an::rt_semantic_excp( parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + " Var - [" + @@ -289,15 +299,14 @@ void sl_func::project(const std::vector &sub_expr, var::scope &c var::struct_sb::project &prj_ref = curr_scope.create_var(sub_expr[0].token_of_subexpr[0].token_val); prj_ref.name_project = sub_expr[0].token_of_subexpr[0].token_val; - prj_ref.lang = (var::struct_sb::language)std::stoi(sub_expr[1].token_of_subexpr[0].token_val); + prj_ref.language = sub_expr[1].token_of_subexpr[0].token_val; for (u32t i = 2; i < sub_expr.size(); ++i) prj_ref.src_files.push_back(sub_expr[i].token_of_subexpr[0].token_val); // ??????? - I don't know if this helper function is needed if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) { - if (!curr_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_LANG, (i32t)prj_ref.lang)) - prj_ref.lang = - (var::struct_sb::language)curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_LANG); + if (!curr_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_LANG, prj_ref.language)) + prj_ref.language = curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_LANG); if (!curr_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_VER, prj_ref.version_project.get_str_version())) prj_ref.version_project = @@ -407,7 +416,8 @@ void sl_func::exp_data(const std::vector &sub_expr, var::scope & interpreter::interpreter_exec::config tmp_conf; tmp_conf.filename_interp = sub_expr[0].token_of_subexpr[0].token_val.c_str(); tmp_conf.use_external_scope = 1; - interpreter::interpreter_exec tmp_interpreter(tmp_conf); + interpreter::interpreter_exec tmp_interpreter; + tmp_interpreter.set_config(tmp_conf); tmp_interpreter.set_external_scope(&curr_scope); tmp_interpreter.build_aef(); } @@ -432,7 +442,7 @@ void sl_func::debug_struct(const std::vector &sub_expr var::struct_sb::project &prj_ref = curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); out_str = "Name Project: " + prj_ref.name_project + "\nVersion: " + prj_ref.version_project.get_str_version() + - "\nLang: " + lang_str(prj_ref.lang) + "\nCompiler: " + prj_ref.path_compiler + + "\nLang: " + prj_ref.language + "\nCompiler: " + prj_ref.path_compiler + "\nLinker: " + prj_ref.path_linker + "\nDebug Flags Compiler: " + prj_ref.dflags_compiler + "\nRelease Flags Compiler: " + prj_ref.rflags_compiler + "\nDebug Flags Linker: " + prj_ref.dflags_linker + @@ -612,13 +622,12 @@ void sl_func::lang(const std::vector &sub_expr, var::scope &curr "003"); var::struct_sb::project &prj_ref = curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); - prj_ref.lang = (var::struct_sb::language)std::stoi(sub_expr[1].token_of_subexpr[0].token_val); + prj_ref.language = sub_expr[1].token_of_subexpr[0].token_val; if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) - if (curr_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_LANG) == 1) { - curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_LANG) = (i32t)prj_ref.lang; - } + if (curr_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_LANG) == 1) + curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_LANG) = prj_ref.language; else - curr_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_LANG, (i32t)prj_ref.lang); + curr_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_LANG, prj_ref.language); } void sl_func::generator(const std::vector &sub_expr, var::scope &curr_scope) { @@ -1119,4 +1128,4 @@ void sl_func::use_it_template(const std::vector &sub_expr, var:: } else curr_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_UITTEMPLATES, prj_ref.use_it_templates); -} \ No newline at end of file +} diff --git a/src/bs/lang/static_struct.hpp b/src/bs/lang/static_struct.hpp index 589f9b9..b627f59 100644 --- a/src/bs/lang/static_struct.hpp +++ b/src/bs/lang/static_struct.hpp @@ -4,6 +4,7 @@ #include "../../kernel/high_level/bwtype.h" #include "../bwconf_var.hpp" +#include #include #include #include @@ -28,6 +29,7 @@ #define PRJ_VAR_NAME_SRC_FILES "_SRC_FILES" #define PRJ_VAR_NAME_UTEMPLATES "_USE_TEMPLATES" #define PRJ_VAR_NAME_UITTEMPLATES "_USE_IT_TEMPLATES" +#define PRJ_VAR_NAME_CUSTOM_EXT_FIELDS "_CUSTOM_EXTENSION_FIELDS" // enum of str postfix name var a target #define TRG_VAR_NAME_NPROJECT "_NAME_PROJECT" @@ -79,12 +81,6 @@ namespace var { namespace struct_sb { -enum class language { - c = 0, - cpp, - csharp, - asm_ -}; enum class type_target { exe = 0, lib, @@ -95,17 +91,6 @@ enum class configuration { DEBUG }; -inline std::string lang_str(const language &lang) { - if (lang == language::c) - return "C"; - else if (lang == language::cpp) - return "C++"; - else if (lang == language::csharp) - return "C#"; - else if (lang == language::asm_) - return "ASM"; - return "null"; -} inline std::string target_t_str(const type_target &target_t) { if (target_t == type_target::exe) return "EXECUTABLE"; @@ -123,17 +108,6 @@ inline std::string cfg_str(const configuration &target_t) { return "null"; } -inline language to_lang(std::string lang) { - if (lang == "C") - return language::c; - else if (lang == "C++") - return language::cpp; - else if (lang == "C#") - return language::csharp; - else if (lang == "ASM") - return language::asm_; - return language::c; -} inline type_target to_type_target(std::string target_t) { if (target_t == "EXECUTABLE") return type_target::exe; @@ -214,11 +188,13 @@ struct version { // includes settings that are needed // to generate compilation commands, linking, etc. struct project { - project() = default; + project() { + custom_ext_fields.merge(preset_ext_fields); + } std::string name_project; version version_project; - language lang; + std::string language; std::string path_compiler{DEFAULT_COMPILER_C}, path_linker{DEFAULT_COMPILER_C}; std::string rflags_compiler{RELEASE_FLAGS_COMPILER_CPP}, rflags_linker{RELEASE_FLAGS_LINKER_CXX}; @@ -228,7 +204,12 @@ struct project { bool use_it_templates{0}; std::vector src_files; + std::vector include_paths{"null"}; std::vector vec_templates{"null"}; + + std::map custom_ext_fields{{"null", ""}}; + + static std::map preset_ext_fields; }; // target structure @@ -301,4 +282,4 @@ struct call_component { } // namespace struct_sb } // namespace var -#endif \ No newline at end of file +#endif diff --git a/src/bs/lang/token.hpp b/src/bs/lang/token.hpp index d3c8791..c2ef43c 100644 --- a/src/bs/lang/token.hpp +++ b/src/bs/lang/token.hpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the GNU General Public License 2.0 (GPL-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef TOKEN__H #define TOKEN__H @@ -87,4 +94,4 @@ static inline bool operator==(const token &tk1, const token &tk2) { } } // namespace token_expr -#endif \ No newline at end of file +#endif diff --git a/src/bs/tools/bwexception.hpp b/src/bs/tools/bwexception.hpp index 087f4e3..15470df 100644 --- a/src/bs/tools/bwexception.hpp +++ b/src/bs/tools/bwexception.hpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef EXCEPTION__H #define EXCEPTION__H @@ -15,7 +22,7 @@ class bweas_exception : std::exception { ~bweas_exception() noexcept = default; public: - const char *what() const noexcept{ + const char *what() const noexcept { return ""; } @@ -27,6 +34,6 @@ class bweas_exception : std::exception { // For example: BWS000 std::string assist_err; }; -} // namespace bw_excp +} // namespace bwexception -#endif \ No newline at end of file +#endif diff --git a/src/bs/tools/bwfile.hpp b/src/bs/tools/bwfile.hpp index b7cf44d..50b107e 100644 --- a/src/bs/tools/bwfile.hpp +++ b/src/bs/tools/bwfile.hpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef BWFILE__H #define BWFILE__H @@ -88,4 +95,4 @@ static std::vector file_slc_mask(std::string mask, const std::vecto } // namespace bwfile -#endif \ No newline at end of file +#endif diff --git a/src/bs/tools/bwlua.hpp b/src/bs/tools/bwlua.hpp index 9c4c739..6b4a110 100644 --- a/src/bs/tools/bwlua.hpp +++ b/src/bs/tools/bwlua.hpp @@ -1,8 +1,14 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef BWLUA__H // Header-library bwlua - svec // This library is a wrapper around luajit -// ************************************** #define BWLUA__H #include @@ -10,6 +16,7 @@ #include #include #include +#include #include #include @@ -196,12 +203,21 @@ class lua { throw std::runtime_error(LUA_TABLE_KEYCMP + std::string(op1.type().name())); } }; - template using keyValue = std::pair; + + template using ref = const T &; + template using array = std::vector; - template using fastTable = std::vector>; + template using key_value = std::pair; + template using fast_table = std::vector>; template using table = std::map; + using cfunc = int (*)(lua_State *); + using string_param = std::string_view; + using integer = ptrdiff_t; + using number = double; + + private: template struct is_map : std::false_type {}; template struct is_map> : std::true_type {}; @@ -215,9 +231,6 @@ class lua { template struct is_vec_pairs, A>> : std::true_type {}; - typedef ptrdiff_t integer; - typedef double number; - friend struct symbol; template friend inline void tools::push_stack(lua_State *L, T param); template friend inline T tools::pop_stack(lua_State *L, int idx); @@ -238,7 +251,7 @@ class lua { } public: - std::string get_stack__nmutex() { + std::string get_string_stack() { std::string str = "STACK(" + std::to_string(lua_gettop(L)) + "):\n"; for (ptrdiff_t i = 0; i < lua_gettop(L); ++i) { if (i < lua_gettop(L) - 1) @@ -308,7 +321,7 @@ class lua { template T call_function(std::string name_func, Types... param) { if (!is_created()) return T{}; - lua_getglobal(L, name_func.c_str()); + lua_getglobal(L, name_func.data()); try { return call_symbol(param...); } @@ -317,23 +330,23 @@ class lua { } } - void register_function(std::string name_func, cfunc impl_cfunc) { + void register_function(std::string_view name_func, cfunc impl_cfunc) { lua_pushcfunction(L, impl_cfunc); - lua_setglobal(L, name_func.c_str()); + lua_setglobal(L, name_func.data()); } // execute lua code as a string - void execute_str(std::string str_code) { + void execute_str(std::string_view str_code) { if (!is_created()) return; - if (luaL_dostring(L, str_code.c_str()) != LUA_OK) + if (luaL_dostring(L, str_code.data()) != LUA_OK) LUA_EXCEPTION() } // gets the value of a variable of the given type // Possible types: string, integer, number, boolean and table template T get_var(std::string name_var) { - lua_getglobal(L, name_var.c_str()); + lua_getglobal(L, name_var.data()); try { return get_valsymbol(); @@ -362,11 +375,11 @@ class lua { } // Returns true if exists function(global) in lua state - inline bool is_function(std::string name_func) { + inline bool is_function(std::string_view name_func) { if (!is_created()) return 0; else { - lua_getglobal(L, name_func.c_str()); + lua_getglobal(L, name_func.data()); if (!lua_isfunction(L, -1)) { lua_pop(L, 1); @@ -378,11 +391,11 @@ class lua { } // Returns true if exists variable(global) in lua state - inline bool is_var(std::string name_var) { + inline bool is_var(std::string_view name_var) { if (!is_created()) return 0; else { - lua_getglobal(L, name_var.c_str()); + lua_getglobal(L, name_var.data()); if (lua_isnoneornil(L, -1)) return 0; @@ -395,14 +408,12 @@ class lua { ((push_stack_param>(std::get(tp))), ...); } template void push_stack_param(T param) { - if constexpr (std::is_same_v) - lua_pushstring(L, param); - else if constexpr (std::is_same_v) + if constexpr (std::is_same_v) lua_pushinteger(L, param); else if constexpr (std::is_same_v) lua_pushnumber(L, param); - else if constexpr (std::is_same_v) - lua_pushstring(L, param.c_str()); + else if constexpr (std::is_same_v || std::is_same_v) + lua_pushstring(L, param.data()); else if constexpr (is_map::value) { lua_createtable(L, 0, param.size()); for (const auto &[key, value] : param) { @@ -425,21 +436,21 @@ class lua { lua_settable(L, -3); } else if constexpr (std::is_same_v) { - if (param.type() == typeid(const char *)) - lua_pushstring(L, std::any_cast(param)); - else if (param.type() == typeid(integer)) + if (param.type() == typeid(integer)) lua_pushinteger(L, std::any_cast(param)); else if (param.type() == typeid(number)) lua_pushnumber(L, std::any_cast(param)); else if (param.type() == typeid(std::string)) lua_pushstring(L, std::any_cast(param).c_str()); + else if (param.type() == typeid(std::string_view)) + lua_pushstring(L, std::any_cast(param).data()); else if (param.type() == typeid(std::vector)) push_stack_param(std::any_cast>(param)); else if (param.type() == typeid(std::vector)) push_stack_param(std::any_cast>(param)); - else if (param.type() == typeid(std::vector)) - push_stack_param(std::any_cast>(param)); + else if (param.type() == typeid(std::vector)) + push_stack_param(std::any_cast>(param)); else if (param.type() == typeid(std::vector)) push_stack_param(std::any_cast>(param)); else if (param.type() == typeid(std::vector)) @@ -447,8 +458,8 @@ class lua { else if (param.type() == typeid(table)) push_stack_param(std::any_cast>(param)); - else if (param.type() == typeid(table)) - push_stack_param(std::any_cast>(param)); + else if (param.type() == typeid(table)) + push_stack_param(std::any_cast>(param)); else if (param.type() == typeid(table)) push_stack_param(std::any_cast>(param)); else if (param.type() == typeid(table)) @@ -459,21 +470,21 @@ class lua { push_stack_param(std::any_cast>(param)); else if (param.type() == typeid(table)) push_stack_param(std::any_cast>(param)); - else if (param.type() == typeid(table)) - push_stack_param(std::any_cast>(param)); - - else if (param.type() == typeid(keyValue)) - push_stack_param(std::any_cast>(param)); - else if (param.type() == typeid(keyValue)) - push_stack_param(std::any_cast>(param)); - else if (param.type() == typeid(keyValue)) - push_stack_param(std::any_cast>(param)); - else if (param.type() == typeid(keyValue)) - push_stack_param(std::any_cast>(param)); - else if (param.type() == typeid(keyValue)) - push_stack_param(std::any_cast>(param)); - else if (param.type() == typeid(keyValue)) - push_stack_param(std::any_cast>(param)); + else if (param.type() == typeid(table)) + push_stack_param(std::any_cast>(param)); + + else if (param.type() == typeid(key_value)) + push_stack_param(std::any_cast>(param)); + else if (param.type() == typeid(key_value)) + push_stack_param(std::any_cast>(param)); + else if (param.type() == typeid(key_value)) + push_stack_param(std::any_cast>(param)); + else if (param.type() == typeid(key_value)) + push_stack_param(std::any_cast>(param)); + else if (param.type() == typeid(key_value)) + push_stack_param(std::any_cast>(param)); + else if (param.type() == typeid(key_value)) + push_stack_param(std::any_cast>(param)); else throw std::runtime_error(LUA_PUSH_TYPE_UNK); } @@ -484,17 +495,17 @@ class lua { } template T get_valsymbol(int idx = -1, int pop_last = 1) { std::any value; - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { if (!lua_isstring(L, idx)) throw std::runtime_error(LUA_VARIABLE_NFOUND_STR); - value = lua_tostring(L, idx); + value = std::string(lua_tostring(L, idx)); } - else if constexpr (std::is_same_v) { + else if constexpr (std::is_same_v) { if (!lua_isstring(L, idx)) throw std::runtime_error(LUA_VARIABLE_NFOUND_STR); - value = std::string(lua_tostring(L, idx)); + value = std::string_view(lua_tostring(L, idx)); } else if constexpr (std::is_same_v) { if (!lua_isnumber(L, idx)) @@ -519,7 +530,7 @@ class lua { if (lua_isarray()) value = get_valsymbol>(-1, 0); else if (lua_ispair()) - value = get_valsymbol>(-1, 0); + value = get_valsymbol>(-1, 0); else value = get_valsymbol>(-1, 0); } @@ -674,4 +685,4 @@ template inline T call_function(lua_State *L, Ty } // namespace bwlua -#endif \ No newline at end of file +#endif diff --git a/src/bs/tools/bwlz4.hpp b/src/bs/tools/bwlz4.hpp index a29376e..5e26bad 100644 --- a/src/bs/tools/bwlz4.hpp +++ b/src/bs/tools/bwlz4.hpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef BWLZ4__h #define BWLZ4__h @@ -49,4 +56,4 @@ static inline std::string decompress_data(std::string compress_data, u32t expect } // namespace bwlz4 -#endif \ No newline at end of file +#endif diff --git a/src/bs/tools/call_cmd.hpp b/src/bs/tools/call_cmd.hpp index 7955161..c079ad6 100644 --- a/src/bs/tools/call_cmd.hpp +++ b/src/bs/tools/call_cmd.hpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #ifndef CALL_CMD__H #define CALL_CMD__H @@ -40,4 +47,4 @@ class call_cmd_manager { }; } // namespace tools -#endif \ No newline at end of file +#endif diff --git a/src/bweas.cpp b/src/bweas.cpp index 320a597..b3d0853 100644 --- a/src/bweas.cpp +++ b/src/bweas.cpp @@ -1,3 +1,10 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + #include "bs/bwbuild_sys.hpp" int main(int argv, char **args) { @@ -13,4 +20,4 @@ int main(int argv, char **args) { } return 0; -} \ No newline at end of file +} diff --git a/src/kernel/high_level/assistant.cpp b/src/kernel/high_level/assistant.cpp index ff11f74..b1f27ee 100644 --- a/src/kernel/high_level/assistant.cpp +++ b/src/kernel/high_level/assistant.cpp @@ -109,7 +109,11 @@ bool assistant::exist_file(file_it file) { return 0; return 1; } - +bool assistant::exist_file(std::string name_file) { + if (std::filesystem::exists(name_file)) + return 1; + return 0; +} assistant::file_it assistant::get_iterator_file(std::string name_file) { return std::distance(files.begin(), std::find_if(files.begin(), files.end(), [name_file](const assistant::file &file) { @@ -300,4 +304,4 @@ void assistant::operator<<(std::string text) { #elif defined(UNIX) printf("\033[0m"); #endif -} \ No newline at end of file +} diff --git a/src/kernel/high_level/assistant.hpp b/src/kernel/high_level/assistant.hpp index 84f1ad5..7407840 100644 --- a/src/kernel/high_level/assistant.hpp +++ b/src/kernel/high_level/assistant.hpp @@ -161,6 +161,7 @@ class assistant { void close_file(file_it file); bool exist_file(file_it file); + bool exist_file(std::string name_file); file_it get_iterator_file(std::string name_file); file &get_ref_file(file_it file); @@ -212,8 +213,10 @@ class assistant { private: struct err { - err() = default; - err(std::string _name_e, std::string _desc_e, u32t _ind) : name_e(_name_e), desc_e(_desc_e), ind(_ind) { + public: + err(); + err(std::string_view _name_e, std::string_view _desc_e, u32t _ind) + : name_e(_name_e), desc_e(_desc_e), ind(_ind) { } public: @@ -238,4 +241,4 @@ class assistant { bool current_system_info{0}; }; -#endif \ No newline at end of file +#endif From 4acff9a491c41a5184e808dcc8a3c38b2d060ff1 Mon Sep 17 00:00:00 2001 From: svec1 Date: Sat, 22 Feb 2025 20:16:40 +0000 Subject: [PATCH 03/38] add bweas context --- src/bs/bw_defs.hpp | 10 +++++ src/bs/bwbuild_sys.cpp | 76 ++++++++++++++------------------- src/bs/bwbuild_sys.hpp | 17 +++----- src/bs/bwcache_api.hpp | 50 ++++++++-------------- src/bs/bwcache_fast.cpp | 75 ++++++++++++++++---------------- src/bs/bwcache_json.cpp | 25 +++++------ src/bs/bwcache_lua.cpp | 22 +++++----- src/bs/bwdepends_generator.hpp | 1 + src/bs/bwdepends_integral.hpp | 2 + src/bs/bwgenerator_api.hpp | 14 +++--- src/bs/bwgenerator_integral.cpp | 3 +- src/bs/bwgenerator_lua.cpp | 21 ++++----- src/bs/bwlang.hpp | 18 +++++++- 13 files changed, 160 insertions(+), 174 deletions(-) diff --git a/src/bs/bw_defs.hpp b/src/bs/bw_defs.hpp index d371920..8f3fab2 100644 --- a/src/bs/bw_defs.hpp +++ b/src/bs/bw_defs.hpp @@ -64,6 +64,16 @@ using bwqueue_templates = std::vector; using command = std::string; using commands = std::vector; +// The structure defining the main data for the build +struct bw_context { + std::vector out_targets; + std::vector templates; + std::vector call_components; + std::vector> global_external_args; + + var::struct_sb::target_out *current_target; +}; + namespace bwexception { // Exception class for builder only. diff --git a/src/bs/bwbuild_sys.cpp b/src/bs/bwbuild_sys.cpp index 64bca85..af94518 100644 --- a/src/bs/bwbuild_sys.cpp +++ b/src/bs/bwbuild_sys.cpp @@ -179,12 +179,12 @@ void bwbuilder::init() { throw bwbuilder_excp("Cache generator name expected", "005"); if (config_json["cache-gn"] == "fast_bwcache") - _bwcache = std::unique_ptr(cache_api::base_bwcache::create_fast_bwcache()); + cache = std::unique_ptr(cache_api::base_bwcache::create_fast_bwcache(&context)); else if (config_json["cache-gn"] == "json_bwcache") - _bwcache = std::unique_ptr(cache_api::base_bwcache::create_json_bwcache()); + cache = std::unique_ptr(cache_api::base_bwcache::create_json_bwcache(&context)); } else - _bwcache = std::unique_ptr(cache_api::base_bwcache::create_fast_bwcache()); + cache = std::unique_ptr(cache_api::base_bwcache::create_fast_bwcache(&context)); if (config_json.contains("packages")) { if (!config_json["packages"].is_array()) @@ -206,9 +206,9 @@ void bwbuilder::init() { loaded_package.load(raw_data_package); loaded_packages.push_back(loaded_package); - if (_bwcache == NULL && loaded_package.cfg_package.cache.name_cache == config_json["cache-gn"]) - _bwcache = std::unique_ptr( - cache_api::base_bwcache::create_lua_bwcache(loaded_package.cfg_package.cache.src_lua_cache)); + if (cache == NULL && loaded_package.cfg_package.cache.name_cache == config_json["cache-gn"]) + cache = std::unique_ptr(cache_api::base_bwcache::create_lua_bwcache( + &context, loaded_package.cfg_package.cache.src_lua_cache)); assist.next_output_success(); assist << " - [BWEAS]: The package was loaded successfully(" + std::to_string(raw_data_package.size()) + " bytes)"; @@ -291,7 +291,6 @@ void bwbuilder::switch_output_log(u32t value) { } void bwbuilder::run_interpreter() { - bwlang _bwlang{MAIN_FILE}; _bwlang.load_external_tfuncs(std::move(module_tfuncs)); for (auto loaded_package : loaded_packages) @@ -301,27 +300,20 @@ void bwbuilder::run_interpreter() { _bwlang.execute(); assist << " - [BWEAS]: The interpretation was successful!"; - out_targets = _bwlang.get_targets(); - templates = _bwlang.get_templates(); - call_components = _bwlang.get_call_components(); - global_extern_args = _bwlang.get_global_external_args(); + context = _bwlang.get_context(); } u32t bwbuilder::gen_cache_target() { - if (!out_targets.size()) { + if (!context.out_targets.size()) { assist << "Generating a file with a cache will not be performed."; return 1; } + assist << " - [BWEAS]: Generating a cache file..."; file_it bweas_cache = assist.open_file(CACHE_FILE, mf::open::w); - _bwcache->_cache_data.targets_o_p = &out_targets; - _bwcache->_cache_data.templates = templates; - _bwcache->_cache_data.call_components = call_components; - _bwcache->_cache_data.global_external_args = global_extern_args; - - assist.write_file(assist.get_ref_file(bweas_cache), _bwcache->create_cache(), mf::output::write_binary); + assist.write_file(assist.get_ref_file(bweas_cache), cache->create_cache(), mf::output::write_binary); assist.close_file(bweas_cache); assist.next_output_success(); @@ -335,42 +327,37 @@ void bwbuilder::deserl_cache() { assist << " - [BWEAS]: Cache deserialization..."; - _bwcache->get_cache_data(assist.read_file(assist.get_ref_file(bweas_cache))); - - out_targets = _bwcache->_cache_data.targets_o; - templates = _bwcache->_cache_data.templates; - call_components = _bwcache->_cache_data.call_components; - global_extern_args = _bwcache->_cache_data.global_external_args; + cache->extract_cache_data(assist.read_file(assist.get_ref_file(bweas_cache))); assist << " - [BWEAS]: Cache deserialization was successful!"; assist.next_output_success(); - assist << " - [BWEAS]: Was loaded " + std::to_string(templates.size()) + " template of command!"; + assist << " - [BWEAS]: Was loaded " + std::to_string(context.templates.size()) + " template of command!"; } void bwbuilder::build_targets() { assist << " - [BWEAS]: Building targets..."; - global_extern_args.push_back(std::pair("", "")); + context.global_external_args.push_back(std::pair("", "")); - for (u32t i = 0; i < out_targets.size(); ++i) { - if (generators.find(out_targets[i].name_generator) == generators.end()) + for (auto &target : context.out_targets) { + if (generators.find(target.name_generator) == generators.end()) throw bwbuilder_excp("The provided generator as the primary for the current target was not found - " + - out_targets[i].name_target + ": " + out_targets[i].name_generator, + target.name_target + ": " + target.name_generator, "002"); - else if (out_targets[i].prj.vec_templates.size() == 0) - throw bwbuilder_excp("There are no templates for the target - " + out_targets[i].name_target, "002"); + else if (target.prj.vec_templates.size() == 0) + throw bwbuilder_excp("There are no templates for the target - " + target.name_target, "002"); - std::string dir_target = path_bweas_to_build + "/" + out_targets[i].name_target; + std::string dir_target = path_bweas_to_build + "/" + target.name_target; double build_state = 0.f; - bwqueue_templates bw_tcmd = create_queue_target_templates(out_targets[i]); + bwqueue_templates bw_tcmd = create_queue_target_templates(target); - auto ¤t_generator = generators[out_targets[i].name_generator]; + auto ¤t_generator = generators[target.name_generator]; std::unique_ptr depends_files; - bweas::generator_api::data_transfer data_t{&out_targets[i], &bw_tcmd, &call_components, &global_extern_args, - dir_target}; + context.current_target = ⌖ + bweas::generator_api::data_transfer data_t{&context, dir_target}; if (!std::filesystem::is_directory(dir_target)) std::filesystem::create_directories(dir_target); @@ -378,12 +365,11 @@ void bwbuilder::build_targets() { current_generator->init(); if (current_generator->has_build_graph_depends()) - depends_files = - std::make_unique(current_generator, out_targets[i].prj.language, dir_target); + depends_files = std::make_unique(current_generator, target.prj.language, dir_target); else - depends_files = std::make_unique(out_targets[i].prj.language, dir_target); + depends_files = std::make_unique(target.prj.language, dir_target); - for (const auto &name_file : out_targets[i].prj.src_files) { + for (const auto &name_file : target.prj.src_files) { if (!assist.exist_file(name_file)) throw bwbuilder_excp("The target's source file was not found", "002"); std::string name_depends_file = name_file + DEPENDS_FILE_POSTFIX; @@ -395,10 +381,10 @@ void bwbuilder::build_targets() { depends_files->get_string_depends_file(name_file)); } - depends_files->build_graphs_depends_files(out_targets[i].prj.src_files, out_targets[i].prj.include_paths); + depends_files->build_graphs_depends_files(target.prj.src_files, target.prj.include_paths); data_t.dfiles = depends_files->get_graphs_depends_files(); - assist << " - [BWEAS]: Build {" + out_targets[i].name_target + "}"; + assist << " - [BWEAS]: Build {" + target.name_target + "}"; assist.switch_otp(0); @@ -430,9 +416,9 @@ bwqueue_templates bwbuilder::create_queue_target_templates(const var::struct_sb: bwqueue_templates target_queue_templates; for (u32t i = 0; i < target.prj.vec_templates.size(); ++i) { - for (u32t j = 0; j < templates.size(); ++j) - if (target.prj.vec_templates[i] == templates[j].name) - vec_templates_tmp.push_back(templates[j]); + for (const auto &_template : context.templates) + if (target.prj.vec_templates[i] == _template.name) + vec_templates_tmp.push_back(_template); } const auto &it_template = find_if(vec_templates_tmp.begin(), vec_templates_tmp.end(), diff --git a/src/bs/bwbuild_sys.hpp b/src/bs/bwbuild_sys.hpp index 24c918d..9c1e5d0 100644 --- a/src/bs/bwbuild_sys.hpp +++ b/src/bs/bwbuild_sys.hpp @@ -84,10 +84,6 @@ class bwbuilder final { // generates a cache file of all targets that were created by the interpreter u32t gen_cache_target(); - // Generates a dll that will call, based on the current bweasconf.txt, functions for configuration and creation of - // targets. The build will be much faster if the project is large. (No implementation yet) - void gen_DPCM(); - public: // Sets the logging mode void set_logging(); @@ -112,18 +108,15 @@ class bwbuilder final { bwqueue_templates &queue_target_templates); private: - std::unique_ptr _bwcache; - semantic_an::table_func module_tfuncs; + std::unique_ptr cache; + std::map> generators; - module::module_mg module_manager; std::vector loaded_packages; - std::map> generators; + module::module_mg module_manager; + semantic_an::table_func module_tfuncs; - std::vector out_targets; - std::vector templates; - std::vector call_components; - bwargs global_extern_args; + bw_context context; std::string name_bweas_prg; std::string path_bweas_config, path_bweas_to_build{DIRWORK_ENV}; diff --git a/src/bs/bwcache_api.hpp b/src/bs/bwcache_api.hpp index 125feeb..0721aa2 100644 --- a/src/bs/bwcache_api.hpp +++ b/src/bs/bwcache_api.hpp @@ -33,49 +33,36 @@ namespace cache_api { // Abstract class that bases API for creating cache generators class base_bwcache { public: - // A structure that is intermediate for transferring data to be hashed (and back). - struct cache_data { - cache_data() = default; - - public: - std::vector *targets_o_p{NULL}; - - std::vector targets_o; - std::vector templates; - std::vector call_components; - std::vector> global_external_args; - }; - - base_bwcache() = default; + base_bwcache(bw_context *const _context) : context(_context) {}; public: // A function that must be defined in a child class, and return a cache of data virtual std::string create_cache() = 0; // A function that must be defined in a child class and return cache data - virtual const cache_data &get_cache_data(std::string cache_str) = 0; + virtual void extract_cache_data(std::string &&cache_str) = 0; virtual void delete_cache() = 0; // A number of factory functions to create all possible child classes that implement the bwcache cache generator // based on the bwcache API public: - static inline base_bwcache *create_fast_bwcache(); - static inline base_bwcache *create_json_bwcache(); - static inline base_bwcache *create_lua_bwcache(std::string src_lua); + static inline base_bwcache *create_fast_bwcache(bw_context *const _context); + static inline base_bwcache *create_json_bwcache(bw_context *const _context); + static inline base_bwcache *create_lua_bwcache(bw_context *const _context, std::string src_lua); public: - cache_data _cache_data; + bw_context *const context; }; // A basic cache generator that is fast but also creates a hard-to-read cache for humans to use class fast_bwcache final : private base_bwcache { public: - fast_bwcache(); + fast_bwcache(bw_context *const); public: std::string create_cache() override final; - const cache_data &get_cache_data(std::string cache_str) override final; + void extract_cache_data(std::string &&cache_str) override final; void delete_cache() override final; @@ -87,11 +74,11 @@ class fast_bwcache final : private base_bwcache { // but is also slow compared to fast_bwcache class json_bwcache final : private base_bwcache { public: - json_bwcache(); + json_bwcache(bw_context *const); public: std::string create_cache() override final; - const cache_data &get_cache_data(std::string cache_str) override final; + void extract_cache_data(std::string &&cache_str) override final; void delete_cache() override final; @@ -102,12 +89,11 @@ class json_bwcache final : private base_bwcache { // A class providing an API for creating cache generators in lua, based on the bwcache API class lua_bwcache final : private base_bwcache { public: - lua_bwcache() = delete; - lua_bwcache(std::string); + lua_bwcache(bw_context *const, std::string); public: std::string create_cache() override final; - const cache_data &get_cache_data(std::string cache_str) override final; + void extract_cache_data(std::string &&cache_str) override final; void delete_cache() override final; @@ -117,14 +103,14 @@ class lua_bwcache final : private base_bwcache { bwlua::lua lua; }; -base_bwcache *base_bwcache::create_fast_bwcache() { - return (base_bwcache *)new fast_bwcache; +base_bwcache *base_bwcache::create_fast_bwcache(bw_context *const _context) { + return (base_bwcache *)new fast_bwcache(_context); } -base_bwcache *base_bwcache::create_json_bwcache() { - return (base_bwcache *)new json_bwcache; +base_bwcache *base_bwcache::create_json_bwcache(bw_context *const _context) { + return (base_bwcache *)new json_bwcache(_context); } -base_bwcache *base_bwcache::create_lua_bwcache(std::string src_lua) { - return (base_bwcache *)new lua_bwcache(src_lua); +base_bwcache *base_bwcache::create_lua_bwcache(bw_context *const _context, std::string src_lua) { + return (base_bwcache *)new lua_bwcache(_context, src_lua); } } // namespace cache_api diff --git a/src/bs/bwcache_fast.cpp b/src/bs/bwcache_fast.cpp index fa17e3f..0cebad2 100644 --- a/src/bs/bwcache_fast.cpp +++ b/src/bs/bwcache_fast.cpp @@ -13,12 +13,15 @@ using namespace bweas; using namespace cache_api; using namespace bweas::bwexception; -fast_bwcache::fast_bwcache() { +fast_bwcache::fast_bwcache(bw_context *const _context) : base_bwcache(_context) { if (!init_glob_chfast) { assist.add_err("BWS-CACHE000", "Incorrect cache structure"); init_glob_chfast = 1; } + + if (!context) + throw bwcache_excp("", "000"); } void fast_bwcache::delete_cache() { @@ -32,7 +35,10 @@ std::string fast_bwcache::create_cache() { std::unordered_set all_used_globally_args; std::unordered_set all_used_call_component; - const auto &out_targets = _cache_data.targets_o_p != nullptr ? *_cache_data.targets_o_p : _cache_data.targets_o; + const auto &out_targets = context->out_targets; + const auto &templates = context->templates; + const auto &call_components = context->call_components; + const auto &global_external_args = context->global_external_args; for (i32t i = 0; i < out_targets.size(); ++i) { char *prj_v = (char *)&out_targets[i]; @@ -42,7 +48,6 @@ std::string fast_bwcache::create_cache() { std::to_string(out_targets[i].prj.custom_ext_fields.size()) + " " + std::to_string(out_targets[i].target_vec_libs.size()) + " "; for (u32t j = 0; j < sizeof(var::struct_sb::project); j += sizeof(std::string)) { - // version project if (j == sizeof(std::string)) { serel_target_tmp += (*(var::struct_sb::version *)(prj_v + j)).get_str_version() + " " + @@ -81,54 +86,52 @@ std::string fast_bwcache::create_cache() { serel_target_tmp += out_targets[i].target_vec_libs[j] + " "; } - serel_target_tmp += "EOET" + std::to_string(_cache_data.templates.size()) + " "; // end of enum targets + serel_target_tmp += "EOET" + std::to_string(templates.size()) + " "; // end of enum targets - for (u32t i = 0; i < _cache_data.templates.size(); ++i) { - serel_target_tmp += std::to_string(_cache_data.templates[i].name_accept_params.size()) + " " + - std::to_string(_cache_data.templates[i].args.size()) + " " + _cache_data.templates[i].name + - " " + _cache_data.templates[i].name_call_component + " " + - _cache_data.templates[i].returnable + " "; + for (u32t i = 0; i < templates.size(); ++i) { + serel_target_tmp += std::to_string(templates[i].name_accept_params.size()) + " " + + std::to_string(templates[i].args.size()) + " " + templates[i].name + " " + + templates[i].name_call_component + " " + templates[i].returnable + " "; - all_used_call_component.emplace(_cache_data.templates[i].name_call_component); + all_used_call_component.emplace(templates[i].name_call_component); - for (u32t j = 0; j < _cache_data.templates[i].name_accept_params.size(); ++j) - serel_target_tmp += _cache_data.templates[i].name_accept_params[j] + " "; - for (u32t j = 0; j < _cache_data.templates[i].args.size(); ++j) { - if (_cache_data.templates[i].args[j].arg_t == var::struct_sb::template_command::arg::type::extglobal) - all_used_globally_args.emplace(_cache_data.templates[i].args[j].str_arg); - else if (_cache_data.templates[i].args[j].arg_t == var::struct_sb::template_command::arg::type::string) - serel_target_tmp += "\"" + _cache_data.templates[i].args[j].str_arg + "\" "; + for (u32t j = 0; j < templates[i].name_accept_params.size(); ++j) + serel_target_tmp += templates[i].name_accept_params[j] + " "; + for (u32t j = 0; j < templates[i].args.size(); ++j) { + if (templates[i].args[j].arg_t == var::struct_sb::template_command::arg::type::extglobal) + all_used_globally_args.emplace(templates[i].args[j].str_arg); + else if (templates[i].args[j].arg_t == var::struct_sb::template_command::arg::type::string) + serel_target_tmp += "\"" + templates[i].args[j].str_arg + "\" "; else - serel_target_tmp += _cache_data.templates[i].args[j].str_arg + " "; - serel_target_tmp += std::to_string((i32t)_cache_data.templates[i].args[j].arg_t) + " "; + serel_target_tmp += templates[i].args[j].str_arg + " "; + serel_target_tmp += std::to_string((i32t)templates[i].args[j].arg_t) + " "; } } serel_target_tmp += std::to_string(all_used_call_component.size()) + " "; - for (const auto &c_component : all_used_call_component) { - const auto &ref_c_component = - find_if(_cache_data.call_components.begin(), _cache_data.call_components.end(), - [c_component](const var::struct_sb::call_component &ccmp) { return ccmp.name == c_component; }); - serel_target_tmp += ref_c_component->name + " " + ref_c_component->name_program + " " + - ref_c_component->pattern_ret_files + " "; + for (const auto &call_component : all_used_call_component) { + const auto &ref_call_component = find_if( + call_components.begin(), call_components.end(), + [call_component](const var::struct_sb::call_component &ccmp) { return ccmp.name == call_component; }); + serel_target_tmp += ref_call_component->name + " " + ref_call_component->name_program + " " + + ref_call_component->pattern_ret_files + " "; } serel_target_tmp += std::to_string(all_used_globally_args.size()) + " "; for (const auto &g_arg : all_used_globally_args) { - const auto &g_arg_it = - std::find_if(_cache_data.global_external_args.begin(), _cache_data.global_external_args.end(), - [g_arg](const std::pair &global_external_arg) { - return global_external_arg.first == g_arg; - }); + const auto &g_arg_it = std::find_if(global_external_args.begin(), global_external_args.end(), + [g_arg](const std::pair &global_external_arg) { + return global_external_arg.first == g_arg; + }); serel_target_tmp += g_arg_it->first + "-\"" + g_arg_it->second + "\" "; } return serel_target_tmp; } -const base_bwcache::cache_data &fast_bwcache::get_cache_data(std::string cache_str) { +void fast_bwcache::extract_cache_data(std::string &&cache_str) { var::struct_sb::target_out trg_tmp; var::struct_sb::template_command tcmd_tmp; var::struct_sb::template_command::arg arg_tmp; @@ -172,11 +175,11 @@ const base_bwcache::cache_data &fast_bwcache::get_cache_data(std::string cache_s std::string name_arg = str_tmp; name_arg.erase(name_arg.find("-")); str_tmp.erase(0, str_tmp.find("-") + 1); - _cache_data.global_external_args.push_back(std::pair(name_arg, str_tmp)); + context->global_external_args.push_back(std::pair(name_arg, str_tmp)); } else if (enum_call_component) { if (offset_byte_ccmp / sizeof(std::string) == 3) { - _cache_data.call_components.push_back(ccmp_tmp); + context->call_components.push_back(ccmp_tmp); offset_byte_ccmp = 0; --size_call_components; @@ -219,7 +222,7 @@ const base_bwcache::cache_data &fast_bwcache::get_cache_data(std::string cache_s } } else if (count_word == 6 + size_internal_args + (size_external_args * 2)) { - _cache_data.templates.push_back(tcmd_tmp); + context->templates.push_back(tcmd_tmp); --size_templates; tcmd_tmp.name_accept_params = {}; @@ -309,7 +312,7 @@ const base_bwcache::cache_data &fast_bwcache::get_cache_data(std::string cache_s trg_tmp.target_vec_libs.push_back(str_tmp); else if (count_word == 18 + size_src_files + size_include_paths + size_vec_templates + size_custom_ext_fields + 5 + size_vec_libs) { - _cache_data.targets_o.push_back(trg_tmp); + context->out_targets.push_back(trg_tmp); trg_tmp.target_vec_libs = {}; trg_tmp.prj.src_files = {}; @@ -347,6 +350,4 @@ const base_bwcache::cache_data &fast_bwcache::get_cache_data(std::string cache_s assist.next_output_unsuccess(); throw bwcache_excp("", "000"); } - - return _cache_data; } diff --git a/src/bs/bwcache_json.cpp b/src/bs/bwcache_json.cpp index 036cfa4..2997dae 100644 --- a/src/bs/bwcache_json.cpp +++ b/src/bs/bwcache_json.cpp @@ -13,7 +13,7 @@ using namespace bweas; using namespace cache_api; using namespace bweas::bwexception; -json_bwcache::json_bwcache() { +json_bwcache::json_bwcache(bw_context *const context) : base_bwcache(context) { if (!init_glob_chjson) { assist.add_err("BWS-CACHE000", "Incorrect json cache structure"); @@ -27,9 +27,8 @@ void json_bwcache::delete_cache() { std::string json_bwcache::create_cache() { nlohmann::json cache_data; - const auto &out_targets = _cache_data.targets_o_p != nullptr ? *_cache_data.targets_o_p : _cache_data.targets_o; - for (const auto &target : out_targets) + for (const auto &target : context->out_targets) cache_data["targets"][target.name_target] = {{"type", var::struct_sb::target_t_str(target.target_t)}, {"configuration", var::struct_sb::cfg_str(target.target_cfg)}, {"version", target.version_target.get_str_version()}, @@ -53,7 +52,7 @@ std::string json_bwcache::create_cache() { {"templates", target.prj.vec_templates}, {"custom_extension_fields", target.prj.custom_ext_fields}}}}; - for (const auto &_template : _cache_data.templates) { + for (const auto &_template : context->templates) { cache_data["templates"][_template.name] = {{"name_call_component", _template.name_call_component}, {"returnable", _template.returnable}, {"accept_params", _template.name_accept_params}}; @@ -61,18 +60,18 @@ std::string json_bwcache::create_cache() { cache_data["templates"][_template.name]["args"].push_back({{"type", arg.arg_t}, {"str", arg.str_arg}}); } - for (const auto &call_component : _cache_data.call_components) + for (const auto &call_component : context->call_components) cache_data["call_components"][call_component.name] = {{"name_program", call_component.name_program}, {"pattern_ret_files", call_component.pattern_ret_files}}; - for (const auto &global_external_arg : _cache_data.global_external_args) + for (const auto &global_external_arg : context->global_external_args) cache_data["global_external_args"].push_back( {{"name", global_external_arg.first}, {"value", global_external_arg.second}}); return cache_data.dump(4); } -const base_bwcache::cache_data &json_bwcache::get_cache_data(std::string cache_str) { +void json_bwcache::extract_cache_data(std::string &&cache_str) { try { nlohmann::json cache_data = nlohmann::json::parse(cache_str); @@ -104,7 +103,8 @@ const base_bwcache::cache_data &json_bwcache::get_cache_data(std::string cache_s target_o_tmp.prj.use_it_templates = prj["use_it_templates"]; target_o_tmp.prj.vec_templates = prj["templates"]; target_o_tmp.prj.custom_ext_fields = prj["custom_extension_fields"]; - _cache_data.targets_o.push_back(target_o_tmp); + + context->out_targets.push_back(target_o_tmp); } for (const auto &_template : cache_data["templates"].items()) { @@ -119,7 +119,7 @@ const base_bwcache::cache_data &json_bwcache::get_cache_data(std::string cache_s template_tmp.args.push_back(var::struct_sb::template_command::arg( arg["str"], (var::struct_sb::template_command::arg::type)arg["type"])); - _cache_data.templates.push_back(template_tmp); + context->templates.push_back(template_tmp); } for (const auto &call_component : cache_data["call_components"].items()) { @@ -130,14 +130,11 @@ const base_bwcache::cache_data &json_bwcache::get_cache_data(std::string cache_s call_component_tmp.name_program = fields["name_program"]; call_component_tmp.pattern_ret_files = fields["pattern_ret_files"]; - _cache_data.call_components.push_back(call_component_tmp); + context->call_components.push_back(call_component_tmp); } for (const auto &call_component : cache_data["global_external_args"].items()) - _cache_data.global_external_args.emplace_back(call_component.value()["name"], - call_component.value()["value"]); - - return _cache_data; + context->global_external_args.emplace_back(call_component.value()["name"], call_component.value()["value"]); } catch (std::exception &what) { throw bwcache_excp(what.what(), "000"); diff --git a/src/bs/bwcache_lua.cpp b/src/bs/bwcache_lua.cpp index 6a3e3d8..e11402e 100644 --- a/src/bs/bwcache_lua.cpp +++ b/src/bs/bwcache_lua.cpp @@ -12,7 +12,7 @@ using namespace bweas; using namespace cache_api; using namespace bweas::bwexception; -lua_bwcache::lua_bwcache(std::string src_lua) { +lua_bwcache::lua_bwcache(bw_context *const _context, std::string src_lua) : base_bwcache(_context) { if (!init_glob_chlua) { assist.add_err("BWS-CACHE000", "Failed to load lua script"); assist.add_err("BWS-CACHE001", "No entry function for creates cache"); @@ -37,23 +37,23 @@ std::string lua_bwcache::create_cache() { std::vector> ltcmd_s; std::vector> lccmp_s; - for (const auto <arget_o : _cache_data.targets_o_p != nullptr ? *_cache_data.targets_o_p : _cache_data.targets_o) + for (const auto <arget_o : context->out_targets) ltargets_o.push_back(bwluatools::conv_to_table(ltarget_o)); - for (const auto <cmd : _cache_data.templates) + for (const auto <cmd : context->templates) ltcmd_s.push_back(bwluatools::conv_to_table(ltcmd)); - for (const auto &lccmp : _cache_data.call_components) + for (const auto &lccmp : context->call_components) lccmp_s.push_back(bwluatools::conv_to_table(lccmp)); try { return lua.call_function( - NAME_FUNCTION_GENERATE_CACHE_LUA, ltargets_o, ltcmd_s, lccmp_s, _cache_data.global_external_args); + NAME_FUNCTION_GENERATE_CACHE_LUA, ltargets_o, ltcmd_s, lccmp_s, context->global_external_args); } catch (std::exception &what) { throw bwcache_excp(what.what(), "000"); } } -const base_bwcache::cache_data &lua_bwcache::get_cache_data(std::string cache_str) { +void lua_bwcache::extract_cache_data(std::string &&cache_str) { std::vector> ltargets_o; std::vector> ltcmd_s; @@ -76,13 +76,11 @@ const base_bwcache::cache_data &lua_bwcache::get_cache_data(std::string cache_st throw bwcache_excp(what.what(), "000"); } for (auto <arget_o : ltargets_o) - _cache_data.targets_o.push_back(bwluatools::conv_to_target(ltarget_o)); + context->out_targets.push_back(bwluatools::conv_to_target(ltarget_o)); for (auto <cmd : ltcmd_s) - _cache_data.templates.push_back(bwluatools::conv_to_template(ltcmd)); + context->templates.push_back(bwluatools::conv_to_template(ltcmd)); for (auto &lccmp : lccmp_s) - _cache_data.call_components.push_back(bwluatools::conv_to_call_components(lccmp)); + context->call_components.push_back(bwluatools::conv_to_call_components(lccmp)); - _cache_data.global_external_args = lglobal_external_args; - - return _cache_data; + context->global_external_args = lglobal_external_args; } diff --git a/src/bs/bwdepends_generator.hpp b/src/bs/bwdepends_generator.hpp index 4fb41e7..91f66d4 100644 --- a/src/bs/bwdepends_generator.hpp +++ b/src/bs/bwdepends_generator.hpp @@ -12,6 +12,7 @@ namespace bweas { +// Implementing a file dependency system based on the bweas generators API class bwdepends_generator : public bweas::bwdepends_files { public: bwdepends_generator(std::shared_ptr _generator, const std::string_view language, diff --git a/src/bs/bwdepends_integral.hpp b/src/bs/bwdepends_integral.hpp index 208787c..96b0d74 100644 --- a/src/bs/bwdepends_integral.hpp +++ b/src/bs/bwdepends_integral.hpp @@ -12,6 +12,8 @@ #include "bwgenerator_integral.hpp" namespace bweas { + +// Implementing an internal file dependency system class bwdepends_integral : public bwdepends_files { public: bwdepends_integral(const std::string_view language, const std::string_view work_directory) diff --git a/src/bs/bwgenerator_api.hpp b/src/bs/bwgenerator_api.hpp index a021188..4779ede 100644 --- a/src/bs/bwgenerator_api.hpp +++ b/src/bs/bwgenerator_api.hpp @@ -47,16 +47,12 @@ using gen_command = std::map; // A temporary structure that allows you to transfer data to the generator and its sub-functions struct data_transfer { - data_transfer(var::struct_sb::target_out *_trg, bwqueue_templates *_trg_templates, - std::vector *_ccmp_s, bwargs *_global_extern_args, - std::string _work_directory) - : trg(_trg), trg_templates(_trg_templates), ccmp_s(_ccmp_s), global_extern_args(_global_extern_args), - work_directory(_work_directory) { + data_transfer(bw_context *const _context, std::string _work_directory) + : context(_context), work_directory(_work_directory) { } - var::struct_sb::target_out *const trg; - bwqueue_templates *const trg_templates; - std::vector *const ccmp_s; - bwargs *const global_extern_args; + + public: + bw_context *const context; bwdepends_files::depends_map dfiles; files_input ifiles; diff --git a/src/bs/bwgenerator_integral.cpp b/src/bs/bwgenerator_integral.cpp index dae1a71..874a9d5 100644 --- a/src/bs/bwgenerator_integral.cpp +++ b/src/bs/bwgenerator_integral.cpp @@ -46,7 +46,8 @@ void integral_generator::get_input_files(data_transfer &data_t) { } gen_command integral_generator::generate_command(data_transfer &data_t) { - generator::tools::parse_basic_args(*data_t.trg, *data_t.trg_templates, *data_t.global_extern_args); + generator::tools::parse_basic_args(*data_t.context->current_target, data_t.context->templates, + data_t.context->global_external_args); return generator_p(data_t); } diff --git a/src/bs/bwgenerator_lua.cpp b/src/bs/bwgenerator_lua.cpp index 83b9f14..e327d9c 100644 --- a/src/bs/bwgenerator_lua.cpp +++ b/src/bs/bwgenerator_lua.cpp @@ -64,17 +64,17 @@ std::unordered_set lua_generator::build_graph_depends_file(std::str void lua_generator::get_input_files(data_transfer &data_t) { bwluatools::array> ccmps; - for (u32t i = 0; i < (*data_t.ccmp_s).size(); ++i) - ccmps.emplace_back(bwluatools::array{(*data_t.ccmp_s)[i].name, (*data_t.ccmp_s)[i].name_program, - (*data_t.ccmp_s)[i].pattern_ret_files}); + for (const auto &call_component : data_t.context->call_components) + ccmps.emplace_back(bwluatools::array{call_component.name, call_component.name_program, + call_component.pattern_ret_files}); bwluatools::array> tcmd_s_vec; - for (u32t i = 0; i < (*data_t.trg_templates).size(); ++i) - tcmd_s_vec.emplace_back(bwluatools::conv_to_table((*data_t.trg_templates)[i])); + for (const auto &_template : data_t.context->templates) + tcmd_s_vec.emplace_back(bwluatools::conv_to_table(_template)); try { lua["CCMPS"] = ccmps; data_t.ifiles = bwlua::lua::to_map(lua.call_function( - NAME_FUNCTION_GET_INPUT_FILE_LUA, bwluatools::conv_to_table(*data_t.trg), tcmd_s_vec, + NAME_FUNCTION_GET_INPUT_FILE_LUA, bwluatools::conv_to_table(*data_t.context->current_target), tcmd_s_vec, bwluatools::conv_to_table(data_t.dfiles))); } catch (std::exception &what) { @@ -84,13 +84,14 @@ void lua_generator::get_input_files(data_transfer &data_t) { gen_command lua_generator::generate_command(data_transfer &data_t) { - generator::tools::parse_basic_args(*data_t.trg, *data_t.trg_templates, *data_t.global_extern_args); + generator::tools::parse_basic_args(*data_t.context->current_target, data_t.context->templates, + data_t.context->global_external_args); std::vector> tcmd_s_vec; - for (u32t i = 0; i < (*data_t.trg_templates).size(); ++i) - tcmd_s_vec.emplace_back(bwluatools::conv_to_table((*data_t.trg_templates)[i])); + for (const auto &_template : data_t.context->templates) + tcmd_s_vec.emplace_back(bwluatools::conv_to_table(_template)); - lua["CURRENT_TARGET"] = bwluatools::conv_to_table(*data_t.trg); + lua["CURRENT_TARGET"] = bwluatools::conv_to_table(*data_t.context->current_target); lua["CURRENT_QUEUE_TEMPLATES"] = tcmd_s_vec; lua["CURRENT_DIR"] = data_t.work_directory; diff --git a/src/bs/bwlang.hpp b/src/bs/bwlang.hpp index ac9beee..9075849 100644 --- a/src/bs/bwlang.hpp +++ b/src/bs/bwlang.hpp @@ -8,7 +8,7 @@ #ifndef BWLANG__H #define BWLANG__H -#include "lang/interpreter.hpp" +#include "bw_defs.hpp" namespace bweas { @@ -16,7 +16,7 @@ namespace bweas { // the standard bweas functions and also provides interaction with the global scope class bwlang { public: - bwlang(std::string bwconf_file = ""); + bwlang(std::string bwconf_file = MAIN_FILE); bwlang(bwlang &&) = delete; bwlang(const bwlang &) = delete; @@ -50,6 +50,9 @@ class bwlang { var::scope &get_global_scope(); template std::vector> &get_class_variables(); + bw_context get_context(); + + private: std::vector get_targets(); std::vector get_templates(); std::vector get_call_components(); @@ -60,6 +63,7 @@ class bwlang { private: interpreter::interpreter_exec interpreter; + bw_context context; }; bwlang::bwlang(std::string bwconf_file) { cfg_intp.debug_output = 0; @@ -145,6 +149,16 @@ void bwlang::load_external_tfuncs(const semantic_an::table_func &tfuncs) { void bwlang::set_custom_ext_fields_project(std::map &custom_ext_fields) { var::struct_sb::project::preset_ext_fields.merge(custom_ext_fields); } + +bw_context bwlang::get_context() { + context.out_targets = get_targets(); + context.templates = get_templates(); + context.call_components = get_call_components(); + context.global_external_args = get_global_external_args(); + + return context; +} + std::vector bwlang::get_targets() { std::vector targets = interpreter.export_targets(); From b71c9c3f8b01f996065d95dc859582e7f5cd8d16 Mon Sep 17 00:00:00 2001 From: svec1 Date: Tue, 13 May 2025 21:15:06 +0000 Subject: [PATCH 04/38] new interpreter and system of logging --- .clang-format | 7 +- CMakeLists.txt | 3 +- src/CMakeLists.txt | 38 +- src/bs/bw_defs.hpp | 100 +- src/bs/bwbuild_sys.cpp | 299 ++--- src/bs/bwbuild_sys.hpp | 24 +- src/bs/bwcache_api.hpp | 12 +- src/bs/bwcache_fast.cpp | 46 +- src/bs/bwcache_json.cpp | 66 +- src/bs/bwcache_lua.cpp | 20 +- src/bs/bwconf_var.hpp | 5 +- src/bs/bwdepends_files.cpp | 2 - src/bs/bwdepends_files.hpp | 5 +- src/bs/bwgenerator_api.hpp | 8 +- src/bs/bwgenerator_integral.cpp | 13 +- src/bs/bwgenerator_lua.cpp | 34 +- src/bs/bwgntools.cpp | 9 +- src/bs/bwgntools.hpp | 2 +- src/bs/bwlang.hpp | 135 +- src/bs/bwlogger.cpp | 58 + src/bs/bwlogger.hpp | 87 ++ src/bs/bwluatools.cpp | 54 +- src/bs/bwluatools.hpp | 19 +- src/bs/bwmacros_platform.h | 33 + src/bs/bwmodule.cpp | 61 +- src/bs/bwmodule.hpp | 31 +- src/bs/bwpackage.cpp | 108 +- src/bs/bwpackage.hpp | 63 +- src/bs/bwtools.cpp | 143 ++ src/bs/bwtools.hpp | 179 +++ src/bs/bwtype.h | 18 + src/bs/lang/expression.hpp | 230 ++-- src/bs/lang/interpreter.cpp | 130 +- src/bs/lang/interpreter.hpp | 84 +- src/bs/lang/lexer.cpp | 232 ---- src/bs/lang/lexer.hpp | 81 -- src/bs/lang/lexer.l | 81 ++ src/bs/lang/parser.cpp | 332 ----- src/bs/lang/parser.hpp | 101 -- src/bs/lang/parser.y | 132 ++ src/bs/lang/parser_utility.cpp | 134 -- src/bs/lang/scope.hpp | 252 ++-- src/bs/lang/semantic_an.cpp | 1094 ++++++---------- src/bs/lang/semantic_an.hpp | 102 +- src/bs/lang/static_linking_func.cpp | 1149 ++++++++--------- src/bs/lang/static_linking_func.hpp | 137 +- src/bs/lang/static_struct.hpp | 10 +- src/bs/lang/token.hpp | 97 -- src/bs/lang/var.hpp | 6 +- src/bs/tools/bwfile.hpp | 5 +- src/bs/tools/bwlua.hpp | 52 +- src/bs/tools/bwlz4.hpp | 12 +- src/bs/tools/call_cmd.hpp | 6 +- src/bweas.cpp | 12 +- src/kernel/high_level/assistant.cpp | 307 ----- src/kernel/high_level/assistant.hpp | 244 ---- src/kernel/high_level/bwmacros_platform.h | 26 - src/kernel/high_level/bwtype.h | 12 - .../high_level/hook_linux_lib/CMakeLists.txt | 3 - .../hook_linux_lib/decl_func_fbwhook.c | 113 -- src/kernel/high_level/hook_winapi.cpp | 152 --- src/kernel/high_level/hook_winapi.hpp | 37 - src/mdef.hpp | 8 - vcpkg.json | 3 +- 64 files changed, 2516 insertions(+), 4542 deletions(-) create mode 100644 src/bs/bwlogger.cpp create mode 100644 src/bs/bwlogger.hpp create mode 100644 src/bs/bwmacros_platform.h create mode 100644 src/bs/bwtools.cpp create mode 100644 src/bs/bwtools.hpp create mode 100644 src/bs/bwtype.h delete mode 100644 src/bs/lang/lexer.cpp delete mode 100644 src/bs/lang/lexer.hpp create mode 100644 src/bs/lang/lexer.l delete mode 100644 src/bs/lang/parser.cpp delete mode 100644 src/bs/lang/parser.hpp create mode 100644 src/bs/lang/parser.y delete mode 100644 src/bs/lang/parser_utility.cpp delete mode 100644 src/bs/lang/token.hpp delete mode 100644 src/kernel/high_level/assistant.cpp delete mode 100644 src/kernel/high_level/assistant.hpp delete mode 100644 src/kernel/high_level/bwmacros_platform.h delete mode 100644 src/kernel/high_level/bwtype.h delete mode 100644 src/kernel/high_level/hook_linux_lib/CMakeLists.txt delete mode 100644 src/kernel/high_level/hook_linux_lib/decl_func_fbwhook.c delete mode 100644 src/kernel/high_level/hook_winapi.cpp delete mode 100644 src/kernel/high_level/hook_winapi.hpp delete mode 100644 src/mdef.hpp diff --git a/.clang-format b/.clang-format index a81ed14..d162989 100644 --- a/.clang-format +++ b/.clang-format @@ -9,4 +9,9 @@ BraceWrapping : AfterEnum: False BeforeElse: True -StatementMacros: [call_err_tk_inf_lex, wrap_interpreter, debug_init_time, debug_mark_time_func] \ No newline at end of file +AlignConsecutiveAssignments: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + +StatementMacros: [call_err_tk_inf_lex, wrap_interpreter, debug_init_time, debug_mark_time_func] diff --git a/CMakeLists.txt b/CMakeLists.txt index 4199b19..b8eb5b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ add_executable(${BW_NAME_PRJ} src/bweas.cpp) target_link_libraries(${BW_NAME_PRJ} PRIVATE slbweas) -include_directories(${BWEAS_INCLUDE}) +include_directories(${BWEAS_INCLUDE} "src/bs/") if(WIN32) file(COPY ${CMAKE_SOURCE_DIR}/bweas-config.json DESTINATION ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}) @@ -33,7 +33,6 @@ else() file(COPY ${CMAKE_SOURCE_DIR}/bweas-config.json DESTINATION ${CMAKE_BINARY_DIR}) install(TARGETS ${BW_NAME_PRJ} DESTINATION bin) - install(TARGETS bwhook_safe DESTINATION bin) install(FILES ${CMAKE_SOURCE_DIR}/bweas-config.json DESTINATION bin) set_target_properties(bweas PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/bin") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4be0d79..6e24e60 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,13 +1,21 @@ project(bweas_slib LANGUAGES CXX C) file(GLOB_RECURSE FILE_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) -list(REMOVE_ITEM FILE_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/bweas.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/kernel/high_level/hook_linux_lib/decl_func_fbwhook.c) -if(NOT WIN32) - list(REMOVE_ITEM FILE_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/kernel/high_level/hook_winapi.cpp) -endif() +list(REMOVE_ITEM FILE_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/bweas.cpp) + +find_package(BISON REQUIRED) +find_package(FLEX REQUIRED) -add_library(${BWEAS_SLIB} STATIC ${FILE_SOURCE}) +bison_target(BW_PARSER + ${CMAKE_CURRENT_SOURCE_DIR}/bs/lang/parser.y + ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp + DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.hpp) +flex_target(BW_LEXER + ${CMAKE_CURRENT_SOURCE_DIR}/bs/lang/lexer.l + ${CMAKE_CURRENT_BINARY_DIR}/lexer.cpp) +add_flex_bison_dependency(BW_LEXER BW_PARSER) + +add_library(${BWEAS_SLIB} STATIC ${FILE_SOURCE} ${BISON_BW_PARSER_OUTPUTS} ${FLEX_BW_LEXER_OUTPUTS}) # Build with vcpkg if(BWEAS_BUILD_VCPKG_N) @@ -17,13 +25,8 @@ if(BWEAS_BUILD_VCPKG_N) find_package(nlohmann_json CONFIG REQUIRED) find_package(lz4 CONFIG REQUIRED) - if(WIN32) - find_path(DETOURS_INCLUDE_DIRS "detours/detours.h") - find_library(DETOURS_LIBRARY detours REQUIRED) - endif() - - set(BWEAS_LIBS ${DETOURS_LIBRARY} ${LuaJIT_LIBRARIES} nlohmann_json::nlohmann_json lz4::lz4) - set(BWEAS_INCLUDE ${DETOURS_INCLUDE_DIRS} ${LuaJIT_INCLUDE_DIRS} CACHE STRING "All header-files for bweas") + set(BWEAS_LIBS ${LuaJIT_LIBRARIES} nlohmann_json::nlohmann_json lz4::lz4) + set(BWEAS_INCLUDE ${LuaJIT_INCLUDE_DIRS} CACHE STRING "All header-files for bweas") message(STATUS "Install package with vcpkg") else() @@ -62,12 +65,7 @@ else() set(BWEAS_INCLUDE ${NLOHMANN_JSON_INCLUDE_INSTALL_DIR} ${LuaJIT_SRC_DIR} CACHE STRING "All header-files for bweas") endif() -set(BWEAS_INCLUDE ${BWEAS_INCLUDE} "kernel/high_level") +set(BWEAS_INCLUDE ${BWEAS_INCLUDE} "bs/") target_link_libraries(${BWEAS_SLIB} PRIVATE ${BWEAS_LIBS}) -include_directories(${BWEAS_INCLUDE}) - -if(NOT WIN32) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernel/high_level/hook_linux_lib) - target_link_libraries(${BWEAS_SLIB} PRIVATE bwhook_safe) -endif() +include_directories(${BWEAS_INCLUDE} ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/bs/bw_defs.hpp b/src/bs/bw_defs.hpp index 8f3fab2..464c4f4 100644 --- a/src/bs/bw_defs.hpp +++ b/src/bs/bw_defs.hpp @@ -10,9 +10,15 @@ // bweas main header file -#include "lang/interpreter.hpp" -#include "tools/bwexception.hpp" +#include +#include +#include + +#include +#include + +#include #include #include @@ -34,34 +40,26 @@ "\n --help - outputs the syntax of the bweas call as well as its possible functions" \ "\n --version - outputs the version of bweas" -// bweas configuration file, defines all packages that should be loaded by the builder -#define JSON_CONFIG_FILE "bweas-config.json" - -// The current file of a project. It defines all target information -#define MAIN_FILE "bweasconf.txt" - -// Cache file, all information about all targets is saved there for quick access, which makes it possible not to -// reinterpret bweasconf.txt -#define CACHE_FILE "bwcache" - -// The name of the directory where the build files will be created -#define DIRWORK_ENV ".bweas" - -// The file in which all actions of the build system will be logged -#define LOG_FILE "bweas-last.log" - -// A postfix (extension) to the file name containing the names of the source file dependencies -#define DEPENDS_FILE_POSTFIX ".d" +#define JSON_CONFIG_FILE \ + "bweas-config.json" // Bweas configuration file, defines all packages that should be loaded by the builder +#define MAIN_FILE "bweasconf.txt" // The current file of a project. It defines all target information +#define CACHE_FILE \ + "bwcache" /* Cache file, all information about all targets is saved there for quick access, which makes it \ + possible not to reinterpret bweasconf.txt*/ +#define BW_FORMAT_PACKAGE ".bweas-package" // Package expansion +#define DIRWORK_ENV ".bweas" // The name of the directory where the build files will be created +#define DEPENDS_FILE_POSTFIX \ + ".d" // A postfix (extension) to the file name containing the names of the source file dependencies namespace bweas { -using bwarg = std::pair; -using bwargs = std::vector; -using bwarg_files = std::pair>; -using bwargs_files = std::vector; +using bwarg = std::pair; +using bwargs = std::vector; +using bwarg_files = std::pair>; +using bwargs_files = std::vector; using bwqueue_templates = std::vector; -using command = std::string; +using command = std::string; using commands = std::vector; // The structure defining the main data for the build @@ -74,58 +72,6 @@ struct bw_context { var::struct_sb::target_out *current_target; }; -namespace bwexception { - -// Exception class for builder only. -class bwbuilder_excp : public ::bwexception::bweas_exception { - public: - bwbuilder_excp(std::string _what_hp, std::string number_err, std::string prefix_err = "") - : what_hp(_what_hp), bweas_exception("BWS" + prefix_err + number_err) { - } - ~bwbuilder_excp() noexcept override = default; - - public: - const char *what() const noexcept override final { - return what_hp.c_str(); - } - - protected: - std::string what_hp; -}; - -// Exception class for bweas-module only. -class bwmodule_excp : public bwbuilder_excp { - public: - bwmodule_excp(std::string _what_hp, std::string number_err) : bwbuilder_excp(_what_hp, number_err, "-MDL") { - } - ~bwmodule_excp() noexcept override final = default; -}; - -// Exception class for bweas-package only. -class bwpackage_excp : public bwbuilder_excp { - public: - bwpackage_excp(std::string _what_hp, std::string number_err) : bwbuilder_excp(_what_hp, number_err, "-PCKG") { - } - ~bwpackage_excp() noexcept override final = default; -}; - -// Exception class for bweas-generator only. -class bwcache_excp : public bwbuilder_excp { - public: - bwcache_excp(std::string _what_hp, std::string number_err) : bwbuilder_excp(_what_hp, number_err, "-CACHE") { - } - ~bwcache_excp() noexcept override final = default; -}; - -// Exception class for bweas-generator only. -class bwgenerator_excp : public bwbuilder_excp { - public: - bwgenerator_excp(std::string _what_hp, std::string number_err) : bwbuilder_excp(_what_hp, number_err, "-GNRT") { - } - ~bwgenerator_excp() noexcept override final = default; -}; -} // namespace bwexception - } // namespace bweas #endif diff --git a/src/bs/bwbuild_sys.cpp b/src/bs/bwbuild_sys.cpp index af94518..2affdaf 100644 --- a/src/bs/bwbuild_sys.cpp +++ b/src/bs/bwbuild_sys.cpp @@ -23,29 +23,13 @@ #include using namespace bweas; -using namespace bweas::bwexception; -using mf = assistant::file::mode_file; -using file_it = assistant::file_it; +using mf = bwtools::file::mode_file; +using file_it = bwtools::file_it; -bwbuilder::bwbuilder(int argv, char **args) { - if (!init_glob) { - assist.add_err("BWS000", "Unable to open configuration file \'bweasconf.txt\'"); - assist.add_err("BWS001", "Incorrect cache structure"); - assist.add_err("BWS002", "Unable to generate command for target"); - assist.add_err("BWS003", "Unable to generate cache"); - assist.add_err("BWS004", "Failed build, external error while calling command"); - assist.add_err("BWS005", "Incorrect structure of the bweas-json configuration file"); - assist.add_err("BWS006", "The bweas-json configuration for package package file was not found"); - assist.add_err("BWS007", "Bweas package not found"); - - assist.add_err("BWS-HAX000", "Unknown parameter"); - assist.add_err("BWS-HAX001", "The package command is a separate subroutine"); - assist.add_err("BWS-HAX002", "The package routine takes two parameters"); - - init_glob = 1; - } +static logger _log{"BWEAS"}; +bwbuilder::bwbuilder(int argv, char **args) { std::vector vec_args; for (u32t i = 0; i < argv; ++i) vec_args.push_back(args[i]); @@ -53,14 +37,15 @@ bwbuilder::bwbuilder(int argv, char **args) { handle_args(vec_args); if (mode_bweas != mode_working::build_package && mode_bweas != mode_working::undef) { - assist << "Initializing system build - bweas " + bwbuilde_ver.get_str_version(); + (_log << bwtools::message) << (log_message(log_type::msg) + << "Initializing system build - bweas " + bwbuilde_ver.get_str_version()); init(); } } void bwbuilder::handle_args(std::vector &args) { args[0].erase(0, args[0].find_last_of("/\\") + 1); - name_bweas_prg = args[0]; + name_bweas_prg = args[0]; path_bweas_config = std::filesystem::current_path().string(); if (args.size() == 1) @@ -72,112 +57,120 @@ void bwbuilder::handle_args(std::vector &args) { bool expected_path_json_cfg_package = 0; for (u32t i = 1; i < args.size(); ++i) { if (args[i].find("--") == 0) { + args[i].erase(args[i].find("--"), 2); + + if (mode_bweas != undef) { + (_log << bwtools::error) << (log_message(log_type::error) + << "Unknown argument: " + args[i] + + ". The bweas mode has already been defined"); + return; + } if (i == 1) expected_path_bweas_config = 0; - args[i].erase(args[i].find("--"), 2); - if (args[i] == "build") { - if (mode_bweas == mode_working::build_package) - throw bwbuilder_excp(args[i], "001", "-HAX"); - if (mode_bweas == mode_working::collect_cfg) - mode_bweas = mode_working::collect_cfg_w_build; - else - mode_bweas = mode_working::build; + if (args[i] == "build") { + mode_bweas = mode_working::build; expected_path_to_build = 1; } else if (args[i] == "cfg") { - if (mode_bweas == mode_working::build) - mode_bweas = mode_working::collect_cfg_w_build; - else - mode_bweas = mode_working::collect_cfg; + mode_bweas = mode_working::collect_cfg; expected_path_bweas_config = 1; } else if (args[i] == "package") { - if ((mode_bweas == mode_working::build || mode_bweas == mode_working::collect_cfg) && i != 2) - throw bwbuilder_excp(path_json_cfg_package, "001", "-HAX"); - mode_bweas = mode_working::build_package; + mode_bweas = mode_working::build_package; expected_path_json_cfg_package = 1; } else if (args[i] == "help") - assist << BWEAS_HELP; + (_log << bwtools::message) << (log_message(log_type::msg) << BWEAS_HELP); else if (args[i] == "version") - assist << BWEAS_INFO; - else - throw bwbuilder_excp("Parameter: " + args[i] + "\n" + BWEAS_HELP, "000", "-HAX"); + (_log << bwtools::message) << (log_message(log_type::msg) << BWEAS_INFO); + else { + (_log << bwtools::error) << (log_message(log_type::error) << "Unknown argument: " + args[i]); + return; + } } else { // --cfg or arg if (expected_path_bweas_config) { path_bweas_config = std::filesystem::absolute(args[i]).string(); - mode_bweas = mode_working::collect_cfg; + mode_bweas = mode_working::collect_cfg; expected_path_bweas_config = 0; } // --build else if (expected_path_to_build) { - path_bweas_to_build = std::filesystem::absolute(args[i]).string(); + path_bweas_to_build = std::filesystem::absolute(args[i]).string(); expected_path_to_build = 0; } // --package else if (expected_path_json_cfg_package) { - path_json_cfg_package = args[i]; + path_json_cfg_package = args[i]; expected_path_json_cfg_package = 0; u32t size_pckg = create_package(path_json_cfg_package); - assist.next_output_important(); - assist << "[Bweas-Package] Created: " + std::to_string(size_pckg) + " bytes"; + (_log << bwtools::message) << (log_message(log_type::msg) + << "[Bweas-Package] Created: " + std::to_string(size_pckg) + " bytes"); + } + else { + (_log << bwtools::error) << (log_message(log_type::error) << "Unknown argument: " + args[i]); + return; } - else - throw bwbuilder_excp("Parameter: " + args[i] + "\n" + BWEAS_HELP, "000", "-HAX"); } } if (expected_path_json_cfg_package) - throw bwbuilder_excp(BWEAS_HELP, "002", "-HAX"); + (_log << bwtools::error) << (log_message(log_type::error) << "Invalid syntax.\n" << BWEAS_HELP); } u32t bwbuilder::create_package(std::string path_json_config_package) { bwpackage::data_bw_package data_package; - const file_it &json_config_package = assist.open_file(path_json_config_package, mf::open::r); - if (!assist.exist_file(json_config_package)) - throw bwbuilder_excp(path_json_config_package, "006"); - - data_package.json_config = assist.read_file(assist.get_ref_file(json_config_package), mf::input::read_default); - assist.close_file(json_config_package); + const file_it &json_config_package = bwtools::open_file(path_json_config_package, mf::open::r); + if (!bwtools::exist_file(json_config_package)) { + (_log << bwtools::error) << (log_message(log_type::error) + << "The bweas-json configuration for package package file was not found"); + return 0; + } + data_package.json_config = bwtools::read_file(bwtools::get_ref_file(json_config_package), mf::input::read_default); + bwtools::close_file(json_config_package); bweas::bwpackage loaded_package; std::string pckg = loaded_package.init(data_package, 1); - const file_it &package = assist.open_file( + if (_log.error_status()) { + (_log << bwtools::error) << (log_message(log_type::error) << "Failed to create a bweas package"); + return 0; + } + const file_it &package = bwtools::open_file( std::filesystem::current_path().string() + "/" + loaded_package.name_package + BW_FORMAT_PACKAGE, mf::open::wb); - assist.write_file(assist.get_ref_file(package), pckg, mf::output::write_binary); - assist.close_file(package); + bwtools::write_file(bwtools::get_ref_file(package), pckg, mf::output::write_binary); + bwtools::close_file(package); return pckg.size(); } void bwbuilder::init() { - std::string bweas_path = assist.get_path_program() + "/" + JSON_CONFIG_FILE; + std::string bweas_path = bwtools::get_path_program() + "/" + JSON_CONFIG_FILE; nlohmann::json config_json; - file_it file_json_config = assist.open_file(bweas_path, mf::open::r); - if (!assist.exist_file(file_json_config)) { - assist.get_ref_file(file_json_config).open(mf::open::w); - assist.write_file(assist.get_ref_file(file_json_config), DEFAULT_BWEAS_JSON_CONFIG); - assist.close_file(file_json_config); + file_it file_json_config = bwtools::open_file(bweas_path, mf::open::r); + if (!bwtools::exist_file(file_json_config)) { + bwtools::get_ref_file(file_json_config).open(mf::open::w); + bwtools::write_file(bwtools::get_ref_file(file_json_config), DEFAULT_BWEAS_JSON_CONFIG); + bwtools::close_file(file_json_config); config_json = nlohmann::json::parse(DEFAULT_BWEAS_JSON_CONFIG); } else { config_json = - nlohmann::json::parse(assist.read_file(assist.get_ref_file(file_json_config), mf::input::read_default)); - assist.close_file(file_json_config); + nlohmann::json::parse(bwtools::read_file(bwtools::get_ref_file(file_json_config), mf::input::read_default)); + bwtools::close_file(file_json_config); } if (config_json.contains("cache-gn")) { - if (!config_json["cache-gn"].is_string()) - throw bwbuilder_excp("Cache generator name expected", "005"); - + if (!config_json["cache-gn"].is_string()) { + (_log << bwtools::error) << (log_message(log_type::error) << "Cache generator name expected"); + return; + } if (config_json["cache-gn"] == "fast_bwcache") cache = std::unique_ptr(cache_api::base_bwcache::create_fast_bwcache(&context)); else if (config_json["cache-gn"] == "json_bwcache") @@ -187,21 +180,28 @@ void bwbuilder::init() { cache = std::unique_ptr(cache_api::base_bwcache::create_fast_bwcache(&context)); if (config_json.contains("packages")) { - if (!config_json["packages"].is_array()) - throw bwbuilder_excp("At least one package must be defined", "005"); + if (!config_json["packages"].is_array()) { + (_log << bwtools::error) << (log_message(log_type::error) + << "Invalid json file structure. At least one package must be defined"); + return; + } for (const auto &package : config_json["packages"].items()) { if (!package.value().is_string()) - throw bwbuilder_excp("Package names are expected", "005"); + (_log << bwtools::error) << (log_message(log_type::error) + << "Invalid json file structure. Package names are expected"); bweas::bwpackage loaded_package; - std::string raw_data_package, path_to_package{assist.get_path_program() + "/packages/" + + std::string raw_data_package, path_to_package{bwtools::get_path_program() + "/packages/" + (std::string)package.value() + BW_FORMAT_PACKAGE}; - file_it it_package = assist.open_file(path_to_package, mf::open::rb); - if (!assist.exist_file(it_package)) - throw bwbuilder_excp(path_to_package, "007"); + file_it it_package = bwtools::open_file(path_to_package, mf::open::rb); + if (!bwtools::exist_file(it_package)) { + (_log << bwtools::warning) + << (log_message(log_type::warning) << "\"" << path_to_package << "\" bweas package not found"); + continue; + } - raw_data_package = assist.read_file(assist.get_ref_file(it_package), mf::input::read_binary); - assist.close_file(it_package); + raw_data_package = bwtools::read_file(bwtools::get_ref_file(it_package), mf::input::read_binary); + bwtools::close_file(it_package); loaded_package.load(raw_data_package); loaded_packages.push_back(loaded_package); @@ -209,9 +209,10 @@ void bwbuilder::init() { if (cache == NULL && loaded_package.cfg_package.cache.name_cache == config_json["cache-gn"]) cache = std::unique_ptr(cache_api::base_bwcache::create_lua_bwcache( &context, loaded_package.cfg_package.cache.src_lua_cache)); - assist.next_output_success(); - assist << " - [BWEAS]: The package was loaded successfully(" + std::to_string(raw_data_package.size()) + - " bytes)"; + _log << bwtools::success + << (log_message(log_type::msg) + << "\"" << path_to_package << "\" bweas package was loaded successfully(" + << raw_data_package.size() << " bytes)"); } } @@ -231,9 +232,9 @@ void bwbuilder::init() { generators[generator.name_generator]->set_use_build_graph_depends(); } for (auto &package : loaded_packages) { - semantic_an::table_func tfuncs = module_manager.init_tsfunc(package.cfg_package.mds); - for (const auto &func : tfuncs) - module_tfuncs.insert(func); + auto module_funcs = module_manager.init_mfuncs(package.cfg_package.modules); + for (const auto &module_func : module_funcs) + external_modules_funcs.push_back(module_func); } } @@ -244,25 +245,20 @@ bwbuilder::mode_working bwbuilder::get_current_mode() { void bwbuilder::start() { if (mode_bweas == mode_working::build_package) return; - file_it bweas_config = assist.open_file(path_bweas_config + "/" MAIN_FILE, mf::open::r); - if (!assist.exist_file(bweas_config)) - assist.call_err("BWS000"); - assist.close_file(bweas_config); + else if (!bwtools::exist_file(path_bweas_config + "/" MAIN_FILE)) + (_log << bwtools::fatal) << (log_message(log_type::fatal) + << "Unable to open configuration file \'bweasconf.txt\'"); if (mode_bweas == mode_working::build) { - std::filesystem::path cache_file = std::filesystem::current_path() / CACHE_FILE; - if (!std::filesystem::exists(cache_file)) { - assist.next_output_unsuccess(); - assist << " - [BWEAS]: Bweas cache not found"; - return; - } + std::string cache_file = bwtools::get_current_path() + "/" + CACHE_FILE; + if (!bwtools::exist_file(cache_file)) + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Bweas cache not found"); std::filesystem::path main_file = std::filesystem::current_path() / MAIN_FILE; std::filesystem::file_time_type cftime = std::filesystem::last_write_time(cache_file); std::filesystem::file_time_type mftime = std::filesystem::last_write_time(main_file); if (mftime >= cftime) { - assist.next_output_important(); - assist << " - [BWEAS]: The configuration file has been modified"; + (_log << bwtools::message) << (log_message(log_type::msg) << "The configuration file has been modified"); goto interpreter_start; } @@ -275,81 +271,75 @@ void bwbuilder::start() { } if (mode_bweas == mode_working::build || mode_bweas == mode_working::collect_cfg_w_build) { - assist.next_output_important(); - assist << "*Build start time: " + assist.get_time(); + (_log << bwtools::message) << (log_message(log_type::msg) << "*Build start time: " << bwtools::get_time()); build_targets(); } } -void bwbuilder::set_logging() { - assist.set_file_log_name(LOG_FILE); -} - -void bwbuilder::switch_output_log(u32t value) { - output_log = value; - assist.switch_otp(output_log); -} - void bwbuilder::run_interpreter() { bwlang _bwlang{MAIN_FILE}; - _bwlang.load_external_tfuncs(std::move(module_tfuncs)); - for (auto loaded_package : loaded_packages) + _bwlang.init_external_funcs(external_modules_funcs); + for (const auto &loaded_package : loaded_packages) _bwlang.set_custom_ext_fields_project(loaded_package.cfg_package.custom_ext_fields_project); - assist << " - [BWEAS]: Interpreting the configuration file..."; + (_log << bwtools::message) << (log_message(log_type::msg) << "Interpreting the configuration file..."); _bwlang.execute(); - assist << " - [BWEAS]: The interpretation was successful!"; + (_log << bwtools::success) << (log_message(log_type::msg) << "The interpretation was successful!"); context = _bwlang.get_context(); } u32t bwbuilder::gen_cache_target() { if (!context.out_targets.size()) { - assist << "Generating a file with a cache will not be performed."; - return 1; + (_log << bwtools::warning) << (log_message(log_type::warning) + << "Generating a file with a cache will not be performed."); + return 0; } - assist << " - [BWEAS]: Generating a cache file..."; + (_log << bwtools::message) << (log_message(log_type::msg) << " - [BWEAS]: Generating a cache file..."); - file_it bweas_cache = assist.open_file(CACHE_FILE, mf::open::w); + file_it bweas_cache = bwtools::open_file(CACHE_FILE, mf::open::w); - assist.write_file(assist.get_ref_file(bweas_cache), cache->create_cache(), mf::output::write_binary); - assist.close_file(bweas_cache); + bwtools::write_file(bwtools::get_ref_file(bweas_cache), cache->create_cache(), mf::output::write_binary); + bwtools::close_file(bweas_cache); - assist.next_output_success(); - assist << " - [BWEAS]: Cache generation was successful!"; + (_log << bwtools::success) << (log_message(log_type::msg) << " - [BWEAS]: Cache generation was successful!"); - return 0; + return 1; } void bwbuilder::deserl_cache() { - file_it bweas_cache = assist.open_file(CACHE_FILE, mf::open::rb); - - assist << " - [BWEAS]: Cache deserialization..."; + file_it bweas_cache = bwtools::open_file(CACHE_FILE, mf::open::rb); - cache->extract_cache_data(assist.read_file(assist.get_ref_file(bweas_cache))); + (_log << bwtools::message) << (log_message(log_type::msg) << "Cache deserialization..."); - assist << " - [BWEAS]: Cache deserialization was successful!"; + cache->extract_cache_data(bwtools::read_file(bwtools::get_ref_file(bweas_cache))); - assist.next_output_success(); - assist << " - [BWEAS]: Was loaded " + std::to_string(context.templates.size()) + " template of command!"; + (_log << bwtools::success) << (log_message(log_type::msg) + << "Cache deserialization was successful!\n" + << "Was loaded " << context.templates.size() << " template of command!"); } void bwbuilder::build_targets() { - assist << " - [BWEAS]: Building targets..."; + (_log << bwtools::message) << (log_message(log_type::msg) << " - [BWEAS]: Building targets..."); context.global_external_args.push_back(std::pair("", "")); for (auto &target : context.out_targets) { - if (generators.find(target.name_generator) == generators.end()) - throw bwbuilder_excp("The provided generator as the primary for the current target was not found - " + - target.name_target + ": " + target.name_generator, - "002"); - else if (target.prj.vec_templates.size() == 0) - throw bwbuilder_excp("There are no templates for the target - " + target.name_target, "002"); - + if (generators.find(target.name_generator) == generators.end()) { + (_log << bwtools::error) + << (log_message(log_type::error) + << "The provided generator as the primary for the current target was not found - " + << target.name_target << ": " << target.name_generator); + return; + } + else if (target.prj.vec_templates.size() == 0) { + (_log << bwtools::error) << (log_message(log_type::error) + << "There are no templates for the target - " << target.name_target); + return; + } std::string dir_target = path_bweas_to_build + "/" + target.name_target; - double build_state = 0.f; + double build_state = 0.f; bwqueue_templates bw_tcmd = create_queue_target_templates(target); @@ -370,41 +360,34 @@ void bwbuilder::build_targets() { depends_files = std::make_unique(target.prj.language, dir_target); for (const auto &name_file : target.prj.src_files) { - if (!assist.exist_file(name_file)) - throw bwbuilder_excp("The target's source file was not found", "002"); std::string name_depends_file = name_file + DEPENDS_FILE_POSTFIX; - if (assist.exist_file(name_depends_file)) + if (bwtools::exist_file(name_depends_file)) depends_files->build_graph_depends_file_string( - name_file, assist.read_file(assist.get_ref_file(assist.open_file(name_depends_file)))); + name_file, bwtools::read_file(bwtools::get_ref_file(bwtools::open_file(name_depends_file)))); else - assist.write_file(assist.get_ref_file(assist.open_file(name_depends_file, mf::open::w)), - depends_files->get_string_depends_file(name_file)); + bwtools::write_file(bwtools::get_ref_file(bwtools::open_file(name_depends_file, mf::open::w)), + depends_files->get_string_depends_file(name_file)); } depends_files->build_graphs_depends_files(target.prj.src_files, target.prj.include_paths); data_t.dfiles = depends_files->get_graphs_depends_files(); - assist << " - [BWEAS]: Build {" + target.name_target + "}"; - - assist.switch_otp(0); + (_log << bwtools::message) << (log_message(log_type::msg) << "Build {" << target.name_target << "}"); current_generator->get_input_files(data_t); auto cmd_s = current_generator->generate_command(data_t); - assist.switch_otp(1); - for (const auto &cmd : cmd_s) { - assist.next_output_important(); - assist << "[" + std::to_string(build_state).erase(std::to_string((u32t)build_state).size() + 3, 4) + - "%]Compile - " + cmd.first; + (_log << bwtools::message) + << (log_message(log_type::msg) + << "[" << std::to_string(build_state).erase(std::to_string((u32t)build_state).size() + 3, 4) + << "%]Compile - " << cmd.first); -#if defined(WIN) if (system(cmd.second.c_str())) -#elif defined(UNIX) - if (((int (*)(const char *))assist.get_realsystem_func())(cmd.second.c_str())) -#endif - throw bwbuilder_excp("Failed build. Command execution error: \n" + cmd.second, "004"); + (_log << bwtools::warning) + << (log_message(log_type::warning) << "Failed build. Command execution error: \n" + << cmd.second); build_state += 1.f / (double)cmd_s.size() * 100; } @@ -427,9 +410,9 @@ bwqueue_templates bwbuilder::create_queue_target_templates(const var::struct_sb: }); if (it_template == vec_templates_tmp.end()) - throw bwbuilder_excp("There is no template that returns a target with the given type - " + - var::struct_sb::target_t_str(target.target_t), - "002"); + (_log << bwtools::fatal) << (log_message(log_type::fatal) + << "There is no template that returns a target with the given type - " + << var::struct_sb::target_t_str(target.target_t)); target_queue_templates.push_back(*it_template); for (u32t i = 0; i < it_template->name_accept_params.size(); ++i) diff --git a/src/bs/bwbuild_sys.hpp b/src/bs/bwbuild_sys.hpp index 9c1e5d0..778c3b8 100644 --- a/src/bs/bwbuild_sys.hpp +++ b/src/bs/bwbuild_sys.hpp @@ -8,11 +8,10 @@ #ifndef BWBUILD_SYS__H #define BWBUILD_SYS__H -#include "../mdef.hpp" - #include #include "bw_defs.hpp" + #include "bwcache_api.hpp" #include "bwgenerator_api.hpp" #include "bwmodule.hpp" @@ -24,12 +23,11 @@ namespace bweas { // parameters to it when launching programs class bwbuilder final { public: - bwbuilder() = delete; bwbuilder(int argv, char **args); - bwbuilder(bwbuilder &&) = delete; - bwbuilder(const bwbuilder &) = delete; - bwbuilder &operator=(bwbuilder &&) = delete; + bwbuilder() = delete; + bwbuilder(const bwbuilder &) = delete; + bwbuilder &operator=(const bwbuilder &) = delete; ~bwbuilder() = default; @@ -84,13 +82,6 @@ class bwbuilder final { // generates a cache file of all targets that were created by the interpreter u32t gen_cache_target(); - public: - // Sets the logging mode - void set_logging(); - - // Sets output to the console, 1 - yes, output all information, 0 - no - void switch_output_log(u32t value); - private: // Collects projects(out_targets) by initializing the generator and calling(bwIGenerator::gen_commands) void build_targets(); @@ -113,8 +104,8 @@ class bwbuilder final { std::vector loaded_packages; - module::module_mg module_manager; - semantic_an::table_func module_tfuncs; + bwmodule_mg module_manager; + std::vector external_modules_funcs; bw_context context; @@ -124,9 +115,6 @@ class bwbuilder final { mode_working mode_bweas{mode_working::undef}; var::struct_sb::version bwbuilde_ver{BWEAS_VERSION_STR}; - bool log{1}, output_log{1}; - - static inline bool init_glob{0}; }; } // namespace bweas diff --git a/src/bs/bwcache_api.hpp b/src/bs/bwcache_api.hpp index 0721aa2..28c52a7 100644 --- a/src/bs/bwcache_api.hpp +++ b/src/bs/bwcache_api.hpp @@ -8,8 +8,8 @@ #ifndef BWCACHE__H #define BWCACHE__H -#include "bw_defs.hpp" -#include "bwluatools.hpp" +#include +#include #define NAME_FUNCTION_GENERATE_CACHE_LUA "create_cache" #define DEFINITION_FUNCTION_GENERATE_CACHE_LUA \ @@ -65,9 +65,6 @@ class fast_bwcache final : private base_bwcache { void extract_cache_data(std::string &&cache_str) override final; void delete_cache() override final; - - private: - static inline bool init_glob_chfast{0}; }; // The second basic cache generator, which in turn has a human readable form, @@ -81,9 +78,6 @@ class json_bwcache final : private base_bwcache { void extract_cache_data(std::string &&cache_str) override final; void delete_cache() override final; - - private: - static inline bool init_glob_chjson{0}; }; // A class providing an API for creating cache generators in lua, based on the bwcache API @@ -98,8 +92,6 @@ class lua_bwcache final : private base_bwcache { void delete_cache() override final; private: - static inline bool init_glob_chlua{0}; - bwlua::lua lua; }; diff --git a/src/bs/bwcache_fast.cpp b/src/bs/bwcache_fast.cpp index 0cebad2..5b324a7 100644 --- a/src/bs/bwcache_fast.cpp +++ b/src/bs/bwcache_fast.cpp @@ -11,17 +11,12 @@ using namespace bweas; using namespace cache_api; -using namespace bweas::bwexception; -fast_bwcache::fast_bwcache(bw_context *const _context) : base_bwcache(_context) { - if (!init_glob_chfast) { - assist.add_err("BWS-CACHE000", "Incorrect cache structure"); - - init_glob_chfast = 1; - } +static logger _log{"BWCACHE[FAST]"}; +fast_bwcache::fast_bwcache(bw_context *const _context) : base_bwcache(_context) { if (!context) - throw bwcache_excp("", "000"); + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Bweas the context is not defined"); } void fast_bwcache::delete_cache() { @@ -35,9 +30,9 @@ std::string fast_bwcache::create_cache() { std::unordered_set all_used_globally_args; std::unordered_set all_used_call_component; - const auto &out_targets = context->out_targets; - const auto &templates = context->templates; - const auto &call_components = context->call_components; + const auto &out_targets = context->out_targets; + const auto &templates = context->templates; + const auto &call_components = context->call_components; const auto &global_external_args = context->global_external_args; for (i32t i = 0; i < out_targets.size(); ++i) { @@ -141,17 +136,17 @@ void fast_bwcache::extract_cache_data(std::string &&cache_str) { i32t count_word = 0, offset_byte_prj = 0, offset_byte_ccmp = 0; i32t size_src_files = 0, size_include_paths, size_vec_templates = 0, size_custom_ext_fields, size_vec_libs = 0; - i32t size_templates = 0; + i32t size_templates = 0; i32t size_internal_args = 0, size_external_args = 0, size_call_components = 0, size_global_extern_args = 0; char *tproj_p = (char *)&trg_tmp.prj; - char *ccmp_p = (char *)&ccmp_tmp; + char *ccmp_p = (char *)&ccmp_tmp; bool is_beg_custom_field = 0; - bool open_sk = 0; - bool enum_templates = 0; - bool enum_call_component = 0; + bool open_sk = 0; + bool enum_templates = 0; + bool enum_call_component = 0; bool enum_global_extern_args = 0; bool expected_arg_param_str = 1; @@ -186,7 +181,7 @@ void fast_bwcache::extract_cache_data(std::string &&cache_str) { if (!size_call_components) { enum_global_extern_args = 1; - enum_call_component = 0; + enum_call_component = 0; size_global_extern_args = std::stoi(str_tmp); goto next; @@ -212,7 +207,7 @@ void fast_bwcache::extract_cache_data(std::string &&cache_str) { count_word < 6 + size_internal_args + (size_external_args * 2)) || count_word == 6 + size_internal_args) { if (expected_arg_param_str) { - arg_tmp.str_arg = str_tmp; + arg_tmp.str_arg = str_tmp; expected_arg_param_str = 0; } else { @@ -226,11 +221,11 @@ void fast_bwcache::extract_cache_data(std::string &&cache_str) { --size_templates; tcmd_tmp.name_accept_params = {}; - tcmd_tmp.args = {}; + tcmd_tmp.args = {}; if (!size_templates) { enum_call_component = 1; - enum_templates = 0; + enum_templates = 0; size_call_components = std::stoi(str_tmp); } @@ -284,7 +279,7 @@ void fast_bwcache::extract_cache_data(std::string &&cache_str) { ; else if (is_beg_custom_field = !is_beg_custom_field) { trg_tmp.prj.custom_ext_fields[str_tmp] = ""; - str_tmp_key = str_tmp; + str_tmp_key = str_tmp; --count_word; } else @@ -314,12 +309,12 @@ void fast_bwcache::extract_cache_data(std::string &&cache_str) { size_custom_ext_fields + 5 + size_vec_libs) { context->out_targets.push_back(trg_tmp); - trg_tmp.target_vec_libs = {}; - trg_tmp.prj.src_files = {}; + trg_tmp.target_vec_libs = {}; + trg_tmp.prj.src_files = {}; trg_tmp.prj.vec_templates = {}; offset_byte_prj = 0; - count_word = 0; + count_word = 0; if (str_tmp.find("EOET") != str_tmp.npos) { str_tmp.erase(0, str_tmp.find("EOET") + 4); @@ -347,7 +342,6 @@ void fast_bwcache::extract_cache_data(std::string &&cache_str) { } } catch (const std::logic_error &_excp) { - assist.next_output_unsuccess(); - throw bwcache_excp("", "000"); + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Invalid structure of the bweas cache file"); } } diff --git a/src/bs/bwcache_json.cpp b/src/bs/bwcache_json.cpp index 2997dae..49ed5a6 100644 --- a/src/bs/bwcache_json.cpp +++ b/src/bs/bwcache_json.cpp @@ -11,16 +11,13 @@ using namespace bweas; using namespace cache_api; -using namespace bweas::bwexception; -json_bwcache::json_bwcache(bw_context *const context) : base_bwcache(context) { - if (!init_glob_chjson) { - assist.add_err("BWS-CACHE000", "Incorrect json cache structure"); +static logger _log{"BWCACHE[JSON]"}; - init_glob_chjson = 1; - } +json_bwcache::json_bwcache(bw_context *const context) : base_bwcache(context) { + if (!context) + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Bweas the context is not defined"); } - void json_bwcache::delete_cache() { delete this; } @@ -79,29 +76,29 @@ void json_bwcache::extract_cache_data(std::string &&cache_str) { var::struct_sb::target_out target_o_tmp; target_o_tmp.name_target = target.key(); - const auto &fields = target.value(); - target_o_tmp.target_t = var::struct_sb::to_type_target(fields["type"]); - target_o_tmp.target_cfg = var::struct_sb::to_cfg(fields["configuration"]); - target_o_tmp.version_target = (std::string)fields["version"]; - target_o_tmp.name_generator = fields["generator"]; + const auto &fields = target.value(); + target_o_tmp.target_t = var::struct_sb::to_type_target(fields["type"]); + target_o_tmp.target_cfg = var::struct_sb::to_cfg(fields["configuration"]); + target_o_tmp.version_target = (std::string)fields["version"]; + target_o_tmp.name_generator = fields["generator"]; target_o_tmp.target_vec_libs = fields["dependencies"]; - const auto &prj = fields["project"]; - target_o_tmp.prj.name_project = prj["name"]; - target_o_tmp.prj.version_project = (std::string)prj["version"]; - target_o_tmp.prj.language = prj["lang"]; - target_o_tmp.prj.path_compiler = prj["path_compiler"]; - target_o_tmp.prj.path_linker = prj["path_linker"]; - target_o_tmp.prj.rflags_compiler = prj["release_flags_compiler"]; - target_o_tmp.prj.rflags_linker = prj["release_flags_linker"]; - target_o_tmp.prj.dflags_compiler = prj["debug_flags_compiler"]; - target_o_tmp.prj.dflags_linker = prj["debug_flags_linker"]; - target_o_tmp.prj.standart_c = prj["std_c"]; - target_o_tmp.prj.standart_cpp = prj["std_cpp"]; - target_o_tmp.prj.src_files = prj["files"]; - target_o_tmp.prj.include_paths = prj["include_paths"]; - target_o_tmp.prj.use_it_templates = prj["use_it_templates"]; - target_o_tmp.prj.vec_templates = prj["templates"]; + const auto &prj = fields["project"]; + target_o_tmp.prj.name_project = prj["name"]; + target_o_tmp.prj.version_project = (std::string)prj["version"]; + target_o_tmp.prj.language = prj["lang"]; + target_o_tmp.prj.path_compiler = prj["path_compiler"]; + target_o_tmp.prj.path_linker = prj["path_linker"]; + target_o_tmp.prj.rflags_compiler = prj["release_flags_compiler"]; + target_o_tmp.prj.rflags_linker = prj["release_flags_linker"]; + target_o_tmp.prj.dflags_compiler = prj["debug_flags_compiler"]; + target_o_tmp.prj.dflags_linker = prj["debug_flags_linker"]; + target_o_tmp.prj.standart_c = prj["std_c"]; + target_o_tmp.prj.standart_cpp = prj["std_cpp"]; + target_o_tmp.prj.src_files = prj["files"]; + target_o_tmp.prj.include_paths = prj["include_paths"]; + target_o_tmp.prj.use_it_templates = prj["use_it_templates"]; + target_o_tmp.prj.vec_templates = prj["templates"]; target_o_tmp.prj.custom_ext_fields = prj["custom_extension_fields"]; context->out_targets.push_back(target_o_tmp); @@ -111,10 +108,10 @@ void json_bwcache::extract_cache_data(std::string &&cache_str) { var::struct_sb::template_command template_tmp; template_tmp.name = _template.key(); - const auto &fields = _template.value(); + const auto &fields = _template.value(); template_tmp.name_call_component = fields["name_call_component"]; - template_tmp.returnable = fields["returnable"]; - template_tmp.name_accept_params = fields["accept_params"]; + template_tmp.returnable = fields["returnable"]; + template_tmp.name_accept_params = fields["accept_params"]; for (const auto &arg : fields["args"]) template_tmp.args.push_back(var::struct_sb::template_command::arg( arg["str"], (var::struct_sb::template_command::arg::type)arg["type"])); @@ -126,8 +123,8 @@ void json_bwcache::extract_cache_data(std::string &&cache_str) { var::struct_sb::call_component call_component_tmp; call_component_tmp.name = call_component.key(); - const auto &fields = call_component.value(); - call_component_tmp.name_program = fields["name_program"]; + const auto &fields = call_component.value(); + call_component_tmp.name_program = fields["name_program"]; call_component_tmp.pattern_ret_files = fields["pattern_ret_files"]; context->call_components.push_back(call_component_tmp); @@ -137,6 +134,7 @@ void json_bwcache::extract_cache_data(std::string &&cache_str) { context->global_external_args.emplace_back(call_component.value()["name"], call_component.value()["value"]); } catch (std::exception &what) { - throw bwcache_excp(what.what(), "000"); + (_log << bwtools::fatal) << (log_message(log_type::fatal) + << "Invalid structure of the bweas cache file: " << what.what()); } } diff --git a/src/bs/bwcache_lua.cpp b/src/bs/bwcache_lua.cpp index e11402e..8a3b5c2 100644 --- a/src/bs/bwcache_lua.cpp +++ b/src/bs/bwcache_lua.cpp @@ -10,22 +10,18 @@ using namespace bweas; using namespace cache_api; -using namespace bweas::bwexception; -lua_bwcache::lua_bwcache(bw_context *const _context, std::string src_lua) : base_bwcache(_context) { - if (!init_glob_chlua) { - assist.add_err("BWS-CACHE000", "Failed to load lua script"); - assist.add_err("BWS-CACHE001", "No entry function for creates cache"); - assist.add_err("BWS-CACHE002", "No entry function for get data of cache"); +static logger _log{"BWCACHE[LUA]"}; - init_glob_chlua = 1; - } +lua_bwcache::lua_bwcache(bw_context *const _context, std::string src_lua) : base_bwcache(_context) { + if (!context) + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Bweas the context is not defined"); lua.create(src_lua); if (!lua.is_function(NAME_FUNCTION_GENERATE_CACHE_LUA)) - throw bwcache_excp("", "001"); + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "No entry function for creates cache"); else if (!lua.is_function(NAME_FUNCTION_GET_DATA_CACHE_LUA)) - throw bwcache_excp("", "002"); + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "No entry function for get data of cache"); } void lua_bwcache::delete_cache() { @@ -49,7 +45,7 @@ std::string lua_bwcache::create_cache() { NAME_FUNCTION_GENERATE_CACHE_LUA, ltargets_o, ltcmd_s, lccmp_s, context->global_external_args); } catch (std::exception &what) { - throw bwcache_excp(what.what(), "000"); + (_log << bwtools::fatal) << (log_message(log_type::fatal) << what.what()); } } @@ -73,7 +69,7 @@ void lua_bwcache::extract_cache_data(std::string &&cache_str) { lua[NAME_VARIABLE_GEARGS_F_EXTERN_LUA].getval>>(); } catch (std::exception &what) { - throw bwcache_excp(what.what(), "000"); + (_log << bwtools::fatal) << (log_message(log_type::fatal) << what.what()); } for (auto <arget_o : ltargets_o) context->out_targets.push_back(bwluatools::conv_to_target(ltarget_o)); diff --git a/src/bs/bwconf_var.hpp b/src/bs/bwconf_var.hpp index 0e85cb2..d429e9a 100644 --- a/src/bs/bwconf_var.hpp +++ b/src/bs/bwconf_var.hpp @@ -8,9 +8,12 @@ #ifndef BWCONF_VAR__H #define BWCONF_VAR__H +#include + #define DEFAULT_BWEAS_JSON_CONFIG \ "{ \ - \"use genlua\": 0 \ + \"cache-gn \": \"fast_bwcache\", \ + \"packages\": [] \ }" #define DEFAULT_BWEAS_GENERATOR "bwgenerator" diff --git a/src/bs/bwdepends_files.cpp b/src/bs/bwdepends_files.cpp index 239aef0..e2f3ef4 100644 --- a/src/bs/bwdepends_files.cpp +++ b/src/bs/bwdepends_files.cpp @@ -5,8 +5,6 @@ // ------------------------------------------ // -#include - #include "bwdepends_files.hpp" bweas::bwdepends_files::depends_map &bweas::bwdepends_files::build_graphs_depends_files( diff --git a/src/bs/bwdepends_files.hpp b/src/bs/bwdepends_files.hpp index 7a60c8b..015d17c 100644 --- a/src/bs/bwdepends_files.hpp +++ b/src/bs/bwdepends_files.hpp @@ -13,7 +13,8 @@ #include #include -#include + +#include namespace bweas { @@ -28,7 +29,7 @@ class bwdepends_files { public: // file, dependencies using depends_file = std::pair>; - using depends_map = std::unordered_map; + using depends_map = std::unordered_map; // Dependency graphs of source files are built depends_map &build_graphs_depends_files(const std::vector &src_files, diff --git a/src/bs/bwgenerator_api.hpp b/src/bs/bwgenerator_api.hpp index 4779ede..e1fb393 100644 --- a/src/bs/bwgenerator_api.hpp +++ b/src/bs/bwgenerator_api.hpp @@ -85,10 +85,10 @@ class interface_generator { } // namespace gninterface -using func_generator = gen_command (*)(data_transfer &); +using func_generator = gen_command (*)(data_transfer &); using func_build_graph_depends_file = std::unordered_set (*)(std::string_view, std::string_view, std::string_view, std::vector); -using func_get_input_files = void (*)(data_transfer &); +using func_get_input_files = void (*)(data_transfer &); // An abstract class that defines the creation of generator classes and is also a generalization class base_generator : public gninterface::interface_generator { @@ -139,8 +139,6 @@ class integral_generator : public base_generator { gen_command generate_command(data_transfer &data_t) override final; private: - static inline bool init_glob_gnint{0}; - func_generator generator_p; func_build_graph_depends_file build_graph_depends_file_p; func_get_input_files get_input_files_p; @@ -164,8 +162,6 @@ class lua_generator : public base_generator { gen_command generate_command(data_transfer &data_t) override final; private: - static inline bool init_glob_gnlua{0}; - bwlua::lua lua; }; diff --git a/src/bs/bwgenerator_integral.cpp b/src/bs/bwgenerator_integral.cpp index 874a9d5..e31e692 100644 --- a/src/bs/bwgenerator_integral.cpp +++ b/src/bs/bwgenerator_integral.cpp @@ -12,20 +12,15 @@ using namespace bweas; using namespace generator_api; using namespace generator; -using namespace bweas::bwexception; + +static logger log{"BWGENERATOR[INTERNAL]"}; integral_generator::integral_generator(func_generator _generator_p, func_build_graph_depends_file _build_graph_depends_file_p, func_get_input_files _get_input_files_p) { - if (!init_glob_gnint) { - assist.add_err("BWS-GNRT000", "Unable to parse basic arguments"); - assist.add_err("BWS-GNRT001", "Internal global argument not found"); - assist.add_err("BWS-GNRT002", "This generator does not have the specified features"); - init_glob_gnint = 1; - } - generator_p = _generator_p; + generator_p = _generator_p; build_graph_depends_file_p = _build_graph_depends_file_p; - get_input_files_p = _get_input_files_p; + get_input_files_p = _get_input_files_p; } void integral_generator::init() { diff --git a/src/bs/bwgenerator_lua.cpp b/src/bs/bwgenerator_lua.cpp index e327d9c..5a6444e 100644 --- a/src/bs/bwgenerator_lua.cpp +++ b/src/bs/bwgenerator_lua.cpp @@ -11,35 +11,25 @@ using namespace bweas; using namespace generator_api; -using namespace bweas::bwexception; -lua_generator::lua_generator(std::string src_lua) { - if (!init_glob_gnlua) { - assist.add_err("BWS-GNRT000", "Unable to parse basic arguments"); - assist.add_err("BWS-GNRT001", "Lua script not loaded"); - assist.add_err("BWS-GNRT002", "Failed to load lua script"); - assist.add_err("BWS-GNRT003", "No entry function for generator"); - assist.add_err("BWS-GNRT004", "Not found function for get input files"); - assist.add_err("BWS-GNRT005", "Run-time error"); - - init_glob_gnlua = 1; - } +static logger log{"BWGENERATOR[LUA]"}; +lua_generator::lua_generator(std::string src_lua) { try { lua.create(src_lua); } catch (std::exception &excp) { - throw bwgenerator_excp(excp.what(), "002"); + (log << bwtools::fatal) << (log_message(log_type::fatal) << "Couldn't load lua code"); } } void lua_generator::init() { if (!lua.is_created()) - throw bwgenerator_excp("", "001"); + (log << bwtools::fatal) << (log_message(log_type::fatal) << "Lua script not loaded"); else if (!lua.is_function(NAME_FUNCTION_GENERATE_COMMAND_LUA)) - throw bwgenerator_excp("", "003"); + (log << bwtools::fatal) << (log_message(log_type::fatal) << "No entry function for generator"); else if (!lua.is_function(NAME_FUNCTION_GET_INPUT_FILE_LUA)) - throw bwgenerator_excp("", "004"); + (log << bwtools::fatal) << (log_message(log_type::fatal) << "No entry function for get input files"); lua["get_name_output_file_lua"] << bwluatools::get_name_output_file_lua; lua["file_slc_mask"] << bwluatools::file_slc_mask_lua; @@ -58,7 +48,7 @@ std::unordered_set lua_generator::build_graph_depends_file(std::str return std::unordered_set{dependencies.begin(), dependencies.end()}; } catch (std::exception &what) { - throw bwgenerator_excp(what.what(), "005"); + (log << bwtools::fatal) << (log_message(log_type::fatal) << "Run-time error" << what.what()); } } @@ -72,13 +62,13 @@ void lua_generator::get_input_files(data_transfer &data_t) { tcmd_s_vec.emplace_back(bwluatools::conv_to_table(_template)); try { - lua["CCMPS"] = ccmps; + lua["CCMPS"] = ccmps; data_t.ifiles = bwlua::lua::to_map(lua.call_function( NAME_FUNCTION_GET_INPUT_FILE_LUA, bwluatools::conv_to_table(*data_t.context->current_target), tcmd_s_vec, bwluatools::conv_to_table(data_t.dfiles))); } catch (std::exception &what) { - throw bwgenerator_excp(what.what(), "005"); + (log << bwtools::fatal) << (log_message(log_type::fatal) << "Run-time error" << what.what()); } } @@ -91,15 +81,15 @@ gen_command lua_generator::generate_command(data_transfer &data_t) { for (const auto &_template : data_t.context->templates) tcmd_s_vec.emplace_back(bwluatools::conv_to_table(_template)); - lua["CURRENT_TARGET"] = bwluatools::conv_to_table(*data_t.context->current_target); + lua["CURRENT_TARGET"] = bwluatools::conv_to_table(*data_t.context->current_target); lua["CURRENT_QUEUE_TEMPLATES"] = tcmd_s_vec; - lua["CURRENT_DIR"] = data_t.work_directory; + lua["CURRENT_DIR"] = data_t.work_directory; try { return bwlua::lua::to_map(lua.call_function( NAME_FUNCTION_GENERATE_COMMAND_LUA, bwlua::lua::to_table(data_t.ifiles))); } catch (std::exception &what) { - throw bwgenerator_excp(what.what(), "004"); + (log << bwtools::fatal) << (log_message(log_type::fatal) << "Run-time error" << what.what()); } } diff --git a/src/bs/bwgntools.cpp b/src/bs/bwgntools.cpp index 6e36e84..b8670ee 100644 --- a/src/bs/bwgntools.cpp +++ b/src/bs/bwgntools.cpp @@ -36,10 +36,8 @@ void generator::tools::parse_basic_args(const var::struct_sb::target_out &target return extern_arg_tmp.first == current_arg.str_arg; }); if (extern_arg == global_extern_args.end()) - throw bwexception::bwgenerator_excp("[" + trg_template.name + - "] The specified external parameter does not exist - " + - current_arg.str_arg, - "000"); + throw "[" + trg_template.name + "] The specified external parameter does not exist - " + + current_arg.str_arg; current_arg.str_arg = extern_arg->second; } @@ -85,8 +83,7 @@ void generator::tools::parse_basic_args(const var::struct_sb::target_out &target else if (current_arg.str_arg.find(NAME_FIELD_PROJECT_SRC_FILES) == 0) continue; else - throw bwexception::bwgenerator_excp( - "[" + trg_template.name + "] There is no such parameter - " + current_arg.str_arg, "000"); + throw "[" + trg_template.name + "] There is no such parameter - " + current_arg.str_arg; } current_arg.arg_t = var::struct_sb::template_command::arg::type::string; diff --git a/src/bs/bwgntools.hpp b/src/bs/bwgntools.hpp index afa77d4..6c2f3e4 100644 --- a/src/bs/bwgntools.hpp +++ b/src/bs/bwgntools.hpp @@ -10,7 +10,7 @@ #include -#include "bw_defs.hpp" +#include namespace bweas { namespace generator { diff --git a/src/bs/bwlang.hpp b/src/bs/bwlang.hpp index 9075849..16ec152 100644 --- a/src/bs/bwlang.hpp +++ b/src/bs/bwlang.hpp @@ -10,41 +10,39 @@ #include "bw_defs.hpp" +#include + namespace bweas { // A wrapper around the bwlang interpreter that installs all // the standard bweas functions and also provides interaction with the global scope class bwlang { public: - bwlang(std::string bwconf_file = MAIN_FILE); + bwlang(std::string_view bwconf_file = MAIN_FILE); - bwlang(bwlang &&) = delete; - bwlang(const bwlang &) = delete; + bwlang(bwlang &&) = delete; + bwlang(const bwlang &) = delete; bwlang &operator=(bwlang &&) = delete; private: // Sets standard functions and keyword operators corresponding to the bweas specification - void set_bwstd_funcs(); - - public: - void set_config(); - void set_bwconf_file(std::string bwconf_file); + void init_scope(); public: // Starts the internal interpreter void execute(); // Loads external functions (passed into this function) into the interpreter (semantic analyzer) - inline void load_external_tfuncs(const semantic_an::table_func &tfuncs); + inline void init_external_funcs(std::vector funcs); // Sets custom extension fields for projects - inline void set_custom_ext_fields_project(std::map &custom_ext_fields); + inline void set_custom_ext_fields_project(std::map custom_ext_fields); template inline bool create_global_var(std::string name_var, T val = {}) { - return interpreter.get_current_scope().try_create_var(name_var, val); + return _interpreter.get_current_scope().try_create_var(name_var, val); } template inline T get_global_var(std::string name_var) { - return interpreter.get_current_scope().get_var_value(name_var); + return _interpreter.get_current_scope().get_var_value(name_var); } var::scope &get_global_scope(); @@ -58,121 +56,106 @@ class bwlang { std::vector get_call_components(); std::vector> get_global_external_args(); - public: - interpreter::interpreter_exec::config cfg_intp; - private: - interpreter::interpreter_exec interpreter; + interpreter _interpreter; bw_context context; }; -bwlang::bwlang(std::string bwconf_file) { - cfg_intp.debug_output = 0; - cfg_intp.filename_interp = bwconf_file; - cfg_intp.transmit_smt_name_func_with_smt = 1; - cfg_intp.use_external_scope = 0; - - interpreter.set_config(cfg_intp); - set_bwstd_funcs(); +bwlang::bwlang(std::string_view bwconf_file) : _interpreter(bwconf_file) { + init_scope(); } -void bwlang::set_bwstd_funcs() { - using namespace aef_expr; +void bwlang::init_scope() { + _interpreter.get_current_scope().create_var("DEBUG", 0); + _interpreter.get_current_scope().create_var("RELEASE", 1); - interpreter.set_std_function( + _interpreter.create_function( "set", sl_func::set, {param_type::NCHECK_VAR_ID, param_type::ANY_VALUE_WITHOUT_FUTUREID_NEXT, param_type::NEXT_TOO}); - interpreter.set_std_function("file", sl_func::file, + _interpreter.create_function("file", sl_func::file, {{param_type::FUTURE_VAR_ID, "{NULL}"}, param_type::LNUM_OR_ID_VAR, param_type::LSTR_OR_ID_VAR, param_type::NEXT_TOO}); - interpreter.set_std_function( + _interpreter.create_function( "project", sl_func::project, - {param_type::FUTURE_VAR_ID, param_type::LSTR_OR_ID_VAR, param_type::LSTR_OR_ID_VAR, param_type::NEXT_TOO}); - interpreter.set_std_function("executable", sl_func::executable, + {param_type::FUTURE_VAR_ID, param_type::LNUM_OR_ID_VAR, param_type::LSTR_OR_ID_VAR, param_type::NEXT_TOO}); + _interpreter.create_function("executable", sl_func::executable, {param_type::FUTURE_VAR_ID, param_type::LNUM_OR_ID_VAR, param_type::VAR_STRUCT_ID}); - interpreter.set_std_function("link_lib", sl_func::link_lib, + _interpreter.create_function("link_lib", sl_func::link_lib, {param_type::VAR_STRUCT_ID, param_type::LSTR_OR_ID_VAR, param_type::NEXT_TOO}); - interpreter.set_std_function("exp_data", sl_func::exp_data, {param_type::LSTR_OR_ID_VAR}); - interpreter.set_std_function("cmd", sl_func::cmd, {param_type::LNUM_OR_ID_VAR, param_type::LSTR_OR_ID_VAR}); - interpreter.set_std_function("debug", sl_func::debug, {param_type::LSTR_OR_ID_VAR, param_type::NEXT_TOO}); - interpreter.set_std_function("debug_struct", sl_func::debug_struct, {param_type::VAR_STRUCT_ID}); + _interpreter.create_function("exp_data", sl_func::exp_data, {param_type::LSTR_OR_ID_VAR}); + _interpreter.create_function("cmd", sl_func::cmd, {param_type::LNUM_OR_ID_VAR, param_type::LSTR_OR_ID_VAR}); + _interpreter.create_function("debug", sl_func::debug, {param_type::LSTR_OR_ID_VAR, param_type::NEXT_TOO}); + _interpreter.create_function("debug_struct", sl_func::debug_struct, {param_type::VAR_STRUCT_ID}); - interpreter.set_std_function( + _interpreter.create_function( "flags_compiler", sl_func::flags_compiler, {param_type::VAR_STRUCT_ID, param_type::LNUM_OR_ID_VAR, param_type::LSTR_OR_ID_VAR, param_type::NEXT_TOO}); - interpreter.set_std_function( + _interpreter.create_function( "flags_linker", sl_func::flags_linker, {param_type::VAR_STRUCT_ID, param_type::LNUM_OR_ID_VAR, param_type::LSTR_OR_ID_VAR, param_type::NEXT_TOO}); - interpreter.set_std_function("path_compiler", sl_func::path_compiler, + _interpreter.create_function("path_compiler", sl_func::path_compiler, {param_type::VAR_STRUCT_ID, param_type::LSTR_OR_ID_VAR}); - interpreter.set_std_function("path_linker", sl_func::path_linker, + _interpreter.create_function("path_linker", sl_func::path_linker, {param_type::VAR_STRUCT_ID, param_type::LSTR_OR_ID_VAR}); - interpreter.set_std_function("standart_c", sl_func::standart_c, + _interpreter.create_function("standart_c", sl_func::standart_c, {param_type::VAR_STRUCT_ID, param_type::LNUM_OR_ID_VAR}); - interpreter.set_std_function("standart_cpp", sl_func::standart_cpp, + _interpreter.create_function("standart_cpp", sl_func::standart_cpp, {param_type::VAR_STRUCT_ID, param_type::LNUM_OR_ID_VAR}); - interpreter.set_std_function("lang", sl_func::lang, {param_type::VAR_STRUCT_ID, param_type::LSTR_OR_ID_VAR}); + _interpreter.create_function("lang", sl_func::lang, {param_type::VAR_STRUCT_ID, param_type::LSTR_OR_ID_VAR}); - interpreter.set_std_function("generator", sl_func::generator, + _interpreter.create_function("generator", sl_func::generator, {param_type::VAR_STRUCT_ID, param_type::LSTR_OR_ID_VAR}); - interpreter.set_std_function("create_templates", sl_func::create_templates, + _interpreter.create_function("create_templates", sl_func::create_templates, {param_type::FUTURE_VAR_ID, param_type::LSTR_OR_ID_VAR}); - interpreter.set_std_function("create_call_component", sl_func::create_call_component, + _interpreter.create_function("create_call_component", sl_func::create_call_component, {param_type::FUTURE_VAR_ID, param_type::LSTR_OR_ID_VAR, param_type::LSTR_OR_ID_VAR}); - interpreter.set_std_function("add_param_template", sl_func::add_param_template, + _interpreter.create_function("add_param_template", sl_func::add_param_template, {param_type::FUTURE_VAR_ID, param_type::VAR_ID}); - interpreter.set_std_function("use_templates", sl_func::use_templates, + _interpreter.create_function("use_templates", sl_func::use_templates, {param_type::VAR_STRUCT_ID, param_type::LSTR_OR_ID_VAR, param_type::NEXT_TOO}); - interpreter.set_std_function("use_it_template", sl_func::use_it_template, + _interpreter.create_function("use_it_template", sl_func::use_it_template, {param_type::VAR_STRUCT_ID, param_type::LNUM_OR_ID_VAR}); } -void bwlang::set_config() { - interpreter.set_config(cfg_intp); -} -void bwlang::set_bwconf_file(std::string bwconf_file) { - cfg_intp.filename_interp = bwconf_file; - interpreter.set_config(cfg_intp); -} void bwlang::execute() { - interpreter.build_aef(); - interpreter.interpret(); + _interpreter.interpret(); } -void bwlang::load_external_tfuncs(const semantic_an::table_func &tfuncs) { - interpreter.load_external_func(tfuncs); +void bwlang::init_external_funcs(std::vector funcs) { + for (const auto &func : funcs) + _interpreter.create_function(func); } -void bwlang::set_custom_ext_fields_project(std::map &custom_ext_fields) { +void bwlang::set_custom_ext_fields_project(std::map custom_ext_fields) { var::struct_sb::project::preset_ext_fields.merge(custom_ext_fields); } bw_context bwlang::get_context() { - context.out_targets = get_targets(); - context.templates = get_templates(); - context.call_components = get_call_components(); + context.out_targets = get_targets(); + context.templates = get_templates(); + context.call_components = get_call_components(); context.global_external_args = get_global_external_args(); return context; } std::vector bwlang::get_targets() { - std::vector targets = interpreter.export_targets(); + std::vector targets = _interpreter.export_targets(); std::vector targets_o; var::struct_sb::target_out target_tmp; for (u32t i = 0; i < targets.size(); ++i) { - target_tmp.name_target = targets[i].name_target; - target_tmp.target_t = targets[i].target_t; - target_tmp.target_cfg = targets[i].target_cfg; - target_tmp.version_target = targets[i].version_target; - target_tmp.name_generator = targets[i].name_generator; + target_tmp.name_target = targets[i].name_target; + target_tmp.target_t = targets[i].target_t; + target_tmp.target_cfg = targets[i].target_cfg; + target_tmp.version_target = targets[i].version_target; + target_tmp.name_generator = targets[i].name_generator; target_tmp.target_vec_libs = targets[i].target_vec_libs; - target_tmp.prj = *targets[i].prj; + target_tmp.prj = *targets[i].prj; targets_o.push_back(target_tmp); } @@ -182,7 +165,7 @@ std::vector bwlang::get_targets() { std::vector bwlang::get_templates() { std::vector> templates = - interpreter.get_current_scope().get_vector_variables_t(); + _interpreter.get_current_scope().get_vector_variables_t(); std::vector templates_out; for (const auto &_template : templates) @@ -193,7 +176,7 @@ std::vector bwlang::get_templates() { std::vector bwlang::get_call_components() { std::vector> call_components = - interpreter.get_current_scope().get_vector_variables_t(); + _interpreter.get_current_scope().get_vector_variables_t(); std::vector call_components_out; for (const auto &_template : call_components) @@ -204,7 +187,7 @@ std::vector bwlang::get_call_components() { std::vector> bwlang::get_global_external_args() { std::vector>> global_external_args = - interpreter.get_current_scope().get_vector_variables_t>(); + _interpreter.get_current_scope().get_vector_variables_t>(); std::vector> global_external_args_out; for (const auto &global_external_arg : global_external_args) @@ -214,10 +197,10 @@ std::vector> bwlang::get_global_external_arg } var::scope &bwlang::get_global_scope() { - return interpreter.get_current_scope(); + return _interpreter.get_current_scope(); } template std::vector> &bwlang::get_class_variables() { - return interpreter.get_current_scope().get_vector_variables_t(); + return _interpreter.get_current_scope().get_vector_variables_t(); } } // namespace bweas diff --git a/src/bs/bwlogger.cpp b/src/bs/bwlogger.cpp new file mode 100644 index 0000000..fde7135 --- /dev/null +++ b/src/bs/bwlogger.cpp @@ -0,0 +1,58 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + +#include + +using namespace bweas; + +bwtools::file_it logger::file_log; +log_type logger::global_status; + +log_message::log_message(log_type _log_t) : log_t(_log_t) { + switch (log_t) { + case log_type::warning: + ss << "[WARNING]: "; + break; + case log_type::error: + ss << "[ERROR]: "; + break; + case log_type::fatal: + ss << "[FATAL]: "; + + case log_type::msg: + default: + break; + } +} +void logger::set_global_status() { + global_status = status; +} +log_type logger::get_status() { + return status; +} +void logger::dump_status() { + status = bweas::log_type::msg; +} +bool logger::error_status() { + return status == log_type::error || status == log_type::fatal; +} + +logger &logger::operator<<(std::function handle_func_callback) { + handle_func = handle_func_callback; + return *this; +} + +void logger::operator<<(const log_message &obj) { + status = obj.log_t; + bwtools::write_file(bwtools::get_ref_file(file_log), + std::string("[") + owner.data() + std::string("]: ") + obj.ss.str()); + + if (handle_func) { + handle_func(std::string("[") + owner.data() + std::string("]: ") + obj.ss.str()); + handle_func = nullptr; + } +} diff --git a/src/bs/bwlogger.hpp b/src/bs/bwlogger.hpp new file mode 100644 index 0000000..f82e9f7 --- /dev/null +++ b/src/bs/bwlogger.hpp @@ -0,0 +1,87 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + +#ifndef LOGGER__H +#define LOGGER__H + +#include +#include + +#include + +#define LOG_FILE "bweas-last.log" // The file in which all actions of the build system will be logged + +namespace bweas { +enum class log_type; +class log_message; +class logger; +} // namespace bweas + +enum class bweas::log_type { + msg = 0, + warning, + error, + fatal +}; + +// The message that the logger accepts +class bweas::log_message { + friend bweas::logger; + + public: + log_message(log_type); + + public: + template log_message &operator<<(const T &obj); + + private: + std::stringstream ss; + bweas::log_type log_t; +}; + +// A class for logging status +class bweas::logger { + public: + using handle_func_t = void(std::string_view); + + public: + logger(std::string_view _owner) : owner(_owner) { + file_log = bwtools::open_file(LOG_FILE, bwtools::file::mode_file::open::w); + } + + logger(const logger &) = delete; + logger &operator=(const logger &) = delete; + + public: + void set_global_status(); + + bweas::log_type get_status(); + void dump_status(); + + bool error_status(); + + public: + logger &operator<<(std::function handle_func_callback); + void operator<<(const bweas::log_message &obj); + + private: + static bwtools::file_it file_log; + static bweas::log_type global_status; + + private: + std::string_view owner; + bweas::log_type status; + + std::function handle_func; +}; + +template bweas::log_message &bweas::log_message::operator<<(const T &obj) { + ss << obj; + return *this; +} + +#endif diff --git a/src/bs/bwluatools.cpp b/src/bs/bwluatools.cpp index a08f6f4..e1c9046 100644 --- a/src/bs/bwluatools.cpp +++ b/src/bs/bwluatools.cpp @@ -78,20 +78,20 @@ bwluatools::table> bwluatools::conv_ var::struct_sb::project bwluatools::conv_to_project(bwluatools::table prj_t) { var::struct_sb::project prj; - prj.name_project = std::any_cast(prj_t[PRJ_VAR_NAME]); - prj.version_project = std::any_cast(prj_t[PRJ_VAR_NAME_VER]); - prj.language = std::any_cast(prj_t[PRJ_VAR_NAME_LANG]); - prj.path_compiler = std::any_cast(prj_t[PRJ_VAR_NAME_PTH_C]); - prj.path_linker = std::any_cast(prj_t[PRJ_VAR_NAME_PTH_L]); - prj.rflags_compiler = std::any_cast(prj_t[PRJ_VAR_NAME_RFLAGS_C]); - prj.rflags_linker = std::any_cast(prj_t[PRJ_VAR_NAME_RFLAGS_L]); - prj.dflags_compiler = std::any_cast(prj_t[PRJ_VAR_NAME_DFLAGS_C]); - prj.dflags_linker = std::any_cast(prj_t[PRJ_VAR_NAME_DFLAGS_L]); - prj.standart_c = std::any_cast(prj_t[PRJ_VAR_NAME_STD_C]); - prj.standart_cpp = std::any_cast(prj_t[PRJ_VAR_NAME_STD_CPP]); - prj.use_it_templates = std::any_cast(prj_t[PRJ_VAR_NAME_UITTEMPLATES]); - prj.src_files = std::any_cast>(prj_t[PRJ_VAR_NAME_SRC_FILES]); - prj.vec_templates = std::any_cast>(prj_t[PRJ_VAR_NAME_UTEMPLATES]); + prj.name_project = std::any_cast(prj_t[PRJ_VAR_NAME]); + prj.version_project = std::any_cast(prj_t[PRJ_VAR_NAME_VER]); + prj.language = std::any_cast(prj_t[PRJ_VAR_NAME_LANG]); + prj.path_compiler = std::any_cast(prj_t[PRJ_VAR_NAME_PTH_C]); + prj.path_linker = std::any_cast(prj_t[PRJ_VAR_NAME_PTH_L]); + prj.rflags_compiler = std::any_cast(prj_t[PRJ_VAR_NAME_RFLAGS_C]); + prj.rflags_linker = std::any_cast(prj_t[PRJ_VAR_NAME_RFLAGS_L]); + prj.dflags_compiler = std::any_cast(prj_t[PRJ_VAR_NAME_DFLAGS_C]); + prj.dflags_linker = std::any_cast(prj_t[PRJ_VAR_NAME_DFLAGS_L]); + prj.standart_c = std::any_cast(prj_t[PRJ_VAR_NAME_STD_C]); + prj.standart_cpp = std::any_cast(prj_t[PRJ_VAR_NAME_STD_CPP]); + prj.use_it_templates = std::any_cast(prj_t[PRJ_VAR_NAME_UITTEMPLATES]); + prj.src_files = std::any_cast>(prj_t[PRJ_VAR_NAME_SRC_FILES]); + prj.vec_templates = std::any_cast>(prj_t[PRJ_VAR_NAME_UTEMPLATES]); prj.custom_ext_fields = std::any_cast>(prj_t[PRJ_VAR_NAME_CUSTOM_EXT_FIELDS]); return prj; @@ -101,10 +101,10 @@ var::struct_sb::target_out bwluatools::conv_to_target(bwluatools::table>(trg_o_t[TRG_NAME_FIELD_PROJECT])); - trg.target_t = var::struct_sb::to_type_target(std::any_cast(trg_o_t[TRG_VAR_NAME_TYPE_T])); - trg.target_cfg = var::struct_sb::to_cfg(std::any_cast(trg_o_t[TRG_VAR_NAME_CFG])); - trg.name_target = std::any_cast(trg_o_t[TRG_NAME_FIELD_NTARGET]); - trg.version_target = std::any_cast(trg_o_t[TRG_VAR_NAME_VER]); + trg.target_t = var::struct_sb::to_type_target(std::any_cast(trg_o_t[TRG_VAR_NAME_TYPE_T])); + trg.target_cfg = var::struct_sb::to_cfg(std::any_cast(trg_o_t[TRG_VAR_NAME_CFG])); + trg.name_target = std::any_cast(trg_o_t[TRG_NAME_FIELD_NTARGET]); + trg.version_target = std::any_cast(trg_o_t[TRG_VAR_NAME_VER]); trg.target_vec_libs = std::any_cast>(trg_o_t[TRG_VAR_NAME_LLIBS]); return trg; @@ -124,7 +124,7 @@ std::vector bwluatools::conv_to_args( var::struct_sb::template_command bwluatools::conv_to_template(bwluatools::table &tcmd) { var::struct_sb::template_command _tcmd; - _tcmd.name = std::any_cast(tcmd[NAME_FIELD_CALL_COMPONENT_NAME]); + _tcmd.name = std::any_cast(tcmd[NAME_FIELD_CALL_COMPONENT_NAME]); _tcmd.name_call_component = std::any_cast(tcmd[NAME_FIELD_TEMPLATE_COMMAND_NAME_CCMP]); _tcmd.name_accept_params = std::any_cast>(tcmd[NAME_FIELD_TEMPLATE_COMMAND_NAME_ACCEPTS_ARGS]); @@ -138,17 +138,17 @@ var::struct_sb::template_command bwluatools::conv_to_template(bwluatools::table< var::struct_sb::call_component bwluatools::conv_to_call_components(bwluatools::table &ccmp) { var::struct_sb::call_component _ccmp; - _ccmp.name = std::any_cast(ccmp[NAME_FIELD_CALL_COMPONENT_NAME]); - _ccmp.name_program = std::any_cast(ccmp[NAME_FIELD_CALL_COMPONENT_NAME_PROGRAM]); + _ccmp.name = std::any_cast(ccmp[NAME_FIELD_CALL_COMPONENT_NAME]); + _ccmp.name_program = std::any_cast(ccmp[NAME_FIELD_CALL_COMPONENT_NAME_PROGRAM]); _ccmp.pattern_ret_files = std::any_cast(ccmp[NAME_FIELD_CALL_COMPONENT_PATTERN_FILES]); return _ccmp; } int bwluatools::get_var(lua_State *L) { - std::string name_var = bwlua::tools::pop_stack(L); + std::string name_var = bwlua::tools::pop_stack(L); bwlua::lua::integer var_t = bwlua::tools::pop_stack(L); - var::scope *ref = (var::scope *)bwlua::tools::pop_stack(L); + var::scope *ref = (var::scope *)bwlua::tools::pop_stack(L); try { if (var_t == 1) bwlua::tools::push_stack(L, (bwlua::lua::integer)ref->get_var_value(name_var)); @@ -178,8 +178,8 @@ int bwluatools::get_var(lua_State *L) { int bwluatools::set_var(lua_State *L) { std::string name_var = bwlua::tools::pop_stack(L); - std::any value = bwlua::tools::pop_stack(L); - var::scope *ref = (var::scope *)bwlua::tools::pop_stack(L); + std::any value = bwlua::tools::pop_stack(L); + var::scope *ref = (var::scope *)bwlua::tools::pop_stack(L); try { if (value.type() == typeid(i32t) && !ref->try_create_var(name_var, std::any_cast(value))) ref->get_var_value(name_var) = std::any_cast(value); @@ -188,7 +188,7 @@ int bwluatools::set_var(lua_State *L) { ref->get_var_value(name_var) = std::any_cast(value); else if (value.type() == typeid(std::vector)) { std::vector any_vec = std::any_cast>(value); - auto el_tmp = std::any_cast(any_vec[0]); + auto el_tmp = std::any_cast(any_vec[0]); if (el_tmp.type() == typeid(i32t)) { std::vector tmp_vec; for (const auto &it : any_vec) @@ -219,7 +219,7 @@ int bwluatools::get_name_output_file_lua(lua_State *L) { } int bwluatools::file_slc_mask_lua(lua_State *L) { commands cmd_s = bwlua::tools::pop_stack(L); - cmd_s = bwfile::file_slc_mask(lua_tostring(L, -2), cmd_s); + cmd_s = bwfile::file_slc_mask(lua_tostring(L, -2), cmd_s); bwlua::tools::push_stack(L, cmd_s); return 1; } diff --git a/src/bs/bwluatools.hpp b/src/bs/bwluatools.hpp index 2ddb60e..2f078c3 100644 --- a/src/bs/bwluatools.hpp +++ b/src/bs/bwluatools.hpp @@ -8,14 +8,13 @@ #ifndef BWLUATOOLS_H #define BWLUATOOLS_H -#include "bwdepends_files.hpp" -#include "bwgntools.hpp" +#include +#include +#include +#include -#include "lang/scope.hpp" -#include "lang/static_struct.hpp" - -#include "tools/bwfile.hpp" -#include "tools/bwlua.hpp" +#include +#include namespace bweas { class bwluatools; @@ -26,12 +25,12 @@ class bweas::bwluatools { public: template using ref = bwlua::lua::ref; - template using array = bwlua::lua::array; + template using array = bwlua::lua::array; template using key_value = bwlua::lua::key_value; - template using table = bwlua::lua::table; + template using table = bwlua::lua::table; using integer = bwlua::lua::integer; - using number = bwlua::lua::number; + using number = bwlua::lua::number; using nil = bwlua::lua::nil; diff --git a/src/bs/bwmacros_platform.h b/src/bs/bwmacros_platform.h new file mode 100644 index 0000000..c76121a --- /dev/null +++ b/src/bs/bwmacros_platform.h @@ -0,0 +1,33 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + +#ifndef BWMACROS__H_ +#define BWMACROS__H_ + +// macro set + +#define _DEBUG + +#if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)) +#define UNIX +#if defined(__linux__) +#define _linux +#elif defined(__APPLE__) && defined(__MACH__) +#define APPLE_OS +#endif +#elif defined(_WIN32) || defined(_WIN64) +#define WIN +#include +#endif + +#if defined(__LP64__) || defined(_M_IA64) || defined(_WIN64) +#define X64 +#else +#define X32 +#endif + +#endif diff --git a/src/bs/bwmodule.cpp b/src/bs/bwmodule.cpp index e64e41e..735422e 100644 --- a/src/bs/bwmodule.cpp +++ b/src/bs/bwmodule.cpp @@ -5,57 +5,26 @@ // ------------------------------------------ // -#include "bwmodule.hpp" +#include using namespace bweas; -using namespace bweas::bwexception; -module::module_mg::module_mg() { - if (!init_glob) { - assist.add_err("BWS-MDL000", "Failed to load module dependent dll file"); - assist.add_err("BWS-MDL001", "Failed to get the specified module function"); +static logger _log{"BWMODULE"}; - init_glob = 1; - } -} - -semantic_an::table_func module::module_mg::init_tfunc(module &md) { - semantic_an::table_func tfuncs; - try { -#if defined(WIN) - HMODULE dll = assist.load_dll(md.name_dll); - if (DWORD it_err = assist.get_error_win32()) - throw bwmodule_excp("WinAPI error: " + std::to_string(it_err), "000"); -#elif defined(UNIX) - u32t dll = assist.load_dl(md.name_dll); - if (!assist.get_error_dl().empty()) - throw bwmodule_excp(assist.get_error_dl(), "000"); -#endif +std::unordered_map bwmodule_mg::lua_stream_s; - for (auto &func : md.funcs) { - func.second.func_ref = (aef_expr::notion_func::func_t)assist.get_ptr_func(md.name_dll, func.first); -#if defined(WIN) - if (DWORD it_err = assist.get_error_win32()) - throw bwmodule_excp("WinAPI error: " + std::to_string(it_err), "001"); -#elif defined(UNIX) - if (!assist.get_error_dl().empty()) - throw bwmodule_excp(assist.get_error_dl(), "001"); -#endif - } - } - catch (bwmodule_excp &_excp) { - throw bwmodule_excp(md.name_dll + std::string(" - Module ") + _excp.what(), - std::string(_excp.get_assist_err()).erase(0, 7)); - } - return md.funcs; -} - -semantic_an::table_func module::module_mg::init_tsfunc(modules &mds) { - semantic_an::table_func tfuncs; +std::vector bwmodule_mg::init_mfuncs(modules &mds) { + std::vector funcs; for (auto &md : mds) { - semantic_an::table_func tfuncs_md = init_tfunc(md); - for (const auto &func_md : tfuncs_md) - tfuncs.insert(func_md); + lua_stream_s.emplace(md.name_module, + bwtools::read_file(bwtools::get_ref_file(bwtools::open_file(md.name_lua_source_file)))); + for (auto &_decl_func : md.funcs) { + _decl_func.func = [md, _decl_func, lua_stream_s](const expressions &expr_s, var::scope &curr_scope) { + lua_stream_s[md.name_module].call_function( + _decl_func.name_func, *((bwluatools::integer *)&expr_s), *((bwluatools::integer *)&curr_scope)); + }; + funcs.push_back(_decl_func); + } } - return tfuncs; + return funcs; } diff --git a/src/bs/bwmodule.hpp b/src/bs/bwmodule.hpp index fc1c962..db7d4d6 100644 --- a/src/bs/bwmodule.hpp +++ b/src/bs/bwmodule.hpp @@ -8,42 +8,37 @@ #ifndef BWMODULE__H #define BWMODULE__H -#include "bw_defs.hpp" +#include +#include namespace bweas { -namespace module { // Class defining modules -class module_mg { +class bwmodule_mg { public: - module_mg(); - ~module_mg() = default; + bwmodule_mg() = default; + ~bwmodule_mg() = default; public: struct module { - module(std::string _name_module, std::string _name_dll, - semantic_an::table_func _funcs) :name_module(_name_module), - name_dll(_name_dll), funcs(_funcs) { + module(std::string _name_module, std::string _name_lua_source_file, + std::vector _funcs) :name_module(_name_module), + name_lua_source_file(_name_lua_source_file), funcs(_funcs) { } std::string name_module; - std::string name_dll; - semantic_an::table_func funcs; + std::string name_lua_source_file; + std::vector funcs; }; using modules = std::vector; public: - // Load the dynamic library corresponding to the passed module, - // and initialize (receive) function pointers - semantic_an::table_func init_tfunc(module &md); - - // Initializes multiple modules, returning a common function table - semantic_an::table_func init_tsfunc(modules &mds); + // Initializes lua modules functions for subsequent calls + std::vector init_mfuncs(modules &mds); private: - static inline bool init_glob{0}; + static std::unordered_map lua_stream_s; }; -} // namespace module } // namespace bweas #endif diff --git a/src/bs/bwpackage.cpp b/src/bs/bwpackage.cpp index 6ba420e..e28c33a 100644 --- a/src/bs/bwpackage.cpp +++ b/src/bs/bwpackage.cpp @@ -11,18 +11,8 @@ #include using namespace bweas; -using namespace bweas::bwexception; -bwpackage::bwpackage() { - if (!init_glob) { - assist.add_err("BWS-PCKG000", "Incorrect bweas package structure"); - assist.add_err("BWS-PCKG001", "The package of this version is not supported by the build system"); - assist.add_err("BWS-PCKG002", "Incorrect json file structure"); - assist.add_err("BWS-PCKG003", "The bweas-lua generator for package file was not found"); - - init_glob = 1; - } -} +static logger _log{"BWPACKAGE"}; std::string bwpackage::create_data_package(data_bw_package _data) { std::string data_str = BW_PACKAGE_PREFIX_BYTE BW_PACKAGE_VERSION + _data.json_config + @@ -37,29 +27,33 @@ std::string bwpackage::create_data_package(data_bw_package _data) { std::string bwpackage::init(data_bw_package _data, bool is_create_pckg) { nlohmann::json config_json = nlohmann::json::parse(_data.json_config); if (!config_json.contains("package-name") || ((name_package = config_json["package-name"]) == "")) - throw bwpackage_excp("Bweas package name field is empty", "002"); + (_log << bwtools::error) << (log_message(log_type::error) << "Bweas package name field is empty"); else if (!config_json.contains("bweas-version") || ((bw_version = var::struct_sb::version(config_json["bweas-version"])) == "0.0.0")) - throw bwpackage_excp("Build system version field is empty", "002"); + (_log << bwtools::error) << (log_message(log_type::error) << "Build system version field is empty"); else if (!config_json.contains("custom_fields_project") && !config_json["custom_fields_project"].is_structured()) - throw bwpackage_excp( - "Definition of custom fields for the project must be in the form of key-value (string and string)", "002"); + (_log << bwtools::error) + << (log_message(log_type::error) + << "Definition of custom fields for the project must be in the form of key-value (string and string)"); + cfg_package.custom_ext_fields_project = config_json["custom_fields_project"]; if (config_json.contains("cache-gn")) { nlohmann::json metainf_ch = config_json["cache-gn"]; if (!metainf_ch.is_structured()) - throw bwpackage_excp("The Cache field must be a structure", "002"); + (_log << bwtools::error) << (log_message(log_type::error) << "The Cache field must be a structure"); + else if (!metainf_ch.contains("name") || !metainf_ch["name"].is_string()) - throw bwpackage_excp("Cache metadata must include its name", "002"); + (_log << bwtools::error) << (log_message(log_type::error) << "Cache metadata must include its name"); else if (!metainf_ch.contains("src-luafile-cache") || !metainf_ch["src-luafile-cache"].is_string()) - throw bwpackage_excp("Cache metadata must include the path to the lua source file", "002"); + (_log << bwtools::error) << (log_message(log_type::error) + << "Cache metadata must include the path to the lua source file"); cfg_package.cache.name_cache = metainf_ch["name"]; if (is_create_pckg) { - cfg_package.cache.src_lua_cache = - assist.read_file(assist.get_ref_file(assist.open_file(metainf_ch["src-luafile-cache"]))); + cfg_package.cache.src_lua_cache = bwtools::read_file( + bwtools::get_ref_file(bwtools::open_file((std::string)metainf_ch["src-luafile-cache"]))); _data.src_lua_cache = cfg_package.cache.src_lua_cache; } else @@ -68,7 +62,8 @@ std::string bwpackage::init(data_bw_package _data, bool is_create_pckg) { // reading lua script file if (config_json.contains("generators")) { if (!config_json["generators"].is_structured()) - throw bwpackage_excp("The \"generators\" field must be of type json structure", "002"); + (_log << bwtools::error) << (log_message(log_type::error) + << "The \"generators\" field must be of type json structure"); u32t i = 0; @@ -76,22 +71,26 @@ std::string bwpackage::init(data_bw_package _data, bool is_create_pckg) { nlohmann::json metainf_gn = generator.value(); if (!metainf_gn.is_object()) - throw bwpackage_excp("The generator meta information unit must be a json object", "002"); + (_log << bwtools::error) << (log_message(log_type::error) + << "The generator meta information unit must be a json object"); else if (!metainf_gn.contains("src-luafile-gen") || !metainf_gn["src-luafile-gen"].is_string()) - throw bwpackage_excp("Generator metadata must include the path to the lua (generator) source code file", - "002"); + (_log << bwtools::error) + << (log_message(log_type::error) + << "Generator metadata must include the path to the lua (generator) source code file"); else if (!metainf_gn.contains("features-generator") || !metainf_gn["features-generator"].is_array()) - throw bwpackage_excp("Generator metadata should include a list of new generator features", "002"); + (_log << bwtools::error) << (log_message(log_type::error) + << "Generator metadata should include a list of new generator features"); else if (config_json.contains("use_custom_search_dependencies") && !config_json["use_custom_search_dependencies"].is_boolean()) - throw bwpackage_excp( - "Definition of custom fields for the project must be in the form of key-value (string and string)", - "002"); - auto it_gnlua_script = assist.open_file(metainf_gn["src-luafile-gen"]); + (_log << bwtools::error) + << (log_message(log_type::error) + << "Definition of custom fields for the project must be in the form of key-value (string and " + "string)"); + auto it_gnlua_script = bwtools::open_file((std::string)metainf_gn["src-luafile-gen"]); if (is_create_pckg) { cfg_package.generators.emplace_back(generator.key(), metainf_gn["features-generator"], metainf_gn["use_custom_search_dependencies"], - assist.read_file(assist.get_ref_file(it_gnlua_script))); + bwtools::read_file(bwtools::get_ref_file(it_gnlua_script))); _data.src_lua_generators.push_back( cfg_package.generators[cfg_package.generators.size() - 1].src_lua_generator); } @@ -105,61 +104,66 @@ std::string bwpackage::init(data_bw_package _data, bool is_create_pckg) { } if (config_json.contains("modules")) { if (!config_json["modules"].is_structured()) - throw bwpackage_excp("The \"generators\" field must be of type json structure", "002"); + (_log << bwtools::error) << (log_message(log_type::error) + << "The \"generators\" field must be of type json structure"); for (const auto &module : config_json["modules"].items()) { nlohmann::json metainf_md = module.value(); - semantic_an::table_func funcs_md; - if (!metainf_md.contains("dll") || !metainf_md["dll"].is_string()) - throw bwpackage_excp("Module metadata must include the name of the dll file", "002"); + std::vector funcs; + if (!metainf_md.contains("lua source file") || !metainf_md["lua source file"].is_string()) + (_log << bwtools::error) << (log_message(log_type::error) + << "Module metadata must include the name of the lua source file"); else if (!metainf_md.contains("functions") || !metainf_md["functions"].is_object()) - throw bwpackage_excp("Module metadata must include the functions they provide for import", "002"); + (_log << bwtools::error) << (log_message(log_type::error) + << "Module metadata must include the functions they provide for import"); for (const auto &func : metainf_md["functions"].items()) { auto it_func = func.value(); - aef_expr::notion_func def_func_tmp; + decl_func def_func_tmp; + def_func_tmp.name_func = func.key(); for (const auto &field : it_func.items()) { if (field.key() == "accepted") { if (!field.value().is_array()) - throw bwpackage_excp( - "The field for listing the types of function parameters must be an array", "002"); + (_log << bwtools::error) + << (log_message(log_type::error) + << "The field for listing the types of function parameters must be an array"); for (u32t i = 0; i < field.value().size(); ++i) { if (field.value()[i].is_string()) def_func_tmp.expected_params.push_back( - aef_expr::param{parser::utility::type_param_in_str(field.value()[i])}); + param{get_string_param_type((std::string)field.value()[i])}); else - def_func_tmp.expected_params.push_back(aef_expr::param{field.value()[i]}); + def_func_tmp.expected_params.push_back(param{field.value()[i]}); } } - else if (field.key() == "csn") { - if (!field.value().is_boolean()) - throw bwpackage_excp( - "Field for selecting the location of the function call, must be an boolean", "002"); - def_func_tmp.only_with_semantic = field.value(); - } } - funcs_md[func.key()] = def_func_tmp; + funcs.push_back(def_func_tmp); } - cfg_package.mds.emplace_back(module.key(), metainf_md["dll"], funcs_md); + cfg_package.modules.emplace_back(module.key(), metainf_md["lua source file"], funcs); } } + + if (_log.error_status()) + return ""; return create_data_package(_data); } -void bwpackage::load(std::string raw_data_package) { +void bwpackage::load(std::string_view raw_data_package) { std::string data_pckg = bwlz4::decompress_data(raw_data_package, MAX_SIZE_BW_PACKAGE); if (data_pckg.size() == 0) - throw bwpackage_excp("Unsuccessful decompression of package bweas", "000"); + (_log << bwtools::error) << (log_message(log_type::error) << "Unsuccessful decompression of package bweas"); if (data_pckg.find(BW_PACKAGE_PREFIX_BYTE) == data_pckg.npos && data_pckg.find(BW_PACKAGE_SEPARATE_JSON_BYTES) == data_pckg.npos) - throw bwpackage_excp("[Package: " + path_to_package + "]", "000"); + (_log << bwtools::error) << (log_message(log_type::error) << "Incorrect bweas package structure" + << "[Package: " << data_pckg.size() << " bytes]"); std::string prefix_package = data_pckg; prefix_package.erase(0, BW_PACKAGE_PREFIX_BYTE_LENGHT); prefix_package.erase(BW_PACKAGE_VERSION_BWEAS_VERSION_LENGHT); if (var::struct_sb::version(prefix_package) < var::struct_sb::version(BW_PACKAGE_PREFIX_BYTE)) - throw bwpackage_excp("[Package: " + path_to_package + "] Ver pckg: " + prefix_package, "001"); + (_log << bwtools::error) << (log_message(log_type::error) + << "The package of this version is not supported by the build system" + << "[Package: " << data_pckg.size() << " bytes] Ver pckg: " << prefix_package); data_pckg.erase(0, BW_PACKAGE_START_BYTES_LENGHT); data_bw_package data_package; diff --git a/src/bs/bwpackage.hpp b/src/bs/bwpackage.hpp index a69bea6..6e72fdd 100644 --- a/src/bs/bwpackage.hpp +++ b/src/bs/bwpackage.hpp @@ -11,53 +11,37 @@ #include "bw_defs.hpp" #include "bwmodule.hpp" -// Package expansion -#define BW_FORMAT_PACKAGE ".bweas-package" - -// The first bytes in the bweas package file are the signature -#define BW_PACKAGE_PREFIX_BYTE "sbw" - -// size in bytes of bweas packet signature -#define BW_PACKAGE_PREFIX_BYTE_LENGHT 3 - -// The bweas version, which is indicated after the signature, for subsequent verification of the package for version -// compliance -#define BW_PACKAGE_VERSION BWEAS_VERSION_MAJOR "." BWEAS_VERSION_MINOR - -// Bweas version length for package -#define BW_PACKAGE_VERSION_BWEAS_VERSION_LENGHT 3 - -// length in bytes of the entire signature (including version) of the bweas package -#define BW_PACKAGE_START_BYTES_LENGHT BW_PACKAGE_PREFIX_BYTE_LENGHT + BW_PACKAGE_VERSION_BWEAS_VERSION_LENGHT +#define BW_PACKAGE_PREFIX_BYTE "sbw" // The first bytes in the bweas package file are the signature +#define BW_PACKAGE_PREFIX_BYTE_LENGHT 3 // Size in bytes of bweas packet signature +#define BW_PACKAGE_VERSION \ + BWEAS_VERSION_MAJOR "." BWEAS_VERSION_MINOR /* The bweas version, which is indicated after the signature, for \ + subsequent verification of the package for version compliance*/ +#define BW_PACKAGE_VERSION_BWEAS_VERSION_LENGHT 3 // Bweas version length for package +#define BW_PACKAGE_START_BYTES_LENGHT \ + BW_PACKAGE_PREFIX_BYTE_LENGHT + \ + BW_PACKAGE_VERSION_BWEAS_VERSION_LENGHT // Length in bytes of the entire signature (including version) of the + // bweas package // Bytes separating the json configuration data and the lua script (indicates the end of the json configuration of the // bweas package) #define BW_PACKAGE_SEPARATE_JSON_BYTES "ejc" +#define BW_PACKAGE_SEPARATE_LUA_CACHE "elc" // Source code separator bytes of cache +#define BW_PACKAGE_SEPARATE_LUA_GENERATE "elg" // Source code separator bytes of generators +#define BW_PACKAGE_SEPARATE_LUA_MODULE "elm" // Source code separator bytes of modules -// Source code separator bytes of cache -#define BW_PACKAGE_SEPARATE_LUA_CACHE "elc" - -// Source code separator bytes of generators -#define BW_PACKAGE_SEPARATE_LUA_GENERATE "elg" +#define BW_PACKAGE_SEPARATE_JSON_BYTES_LENGHT 3 // Length of separating bytes json configuration of the bweas package +#define BW_PACKAGE_SEPARATE_LUA_CACHE_LENGHT 3 // Length of separating bytes between cache source codes +#define BW_PACKAGE_SEPARATE_LUA_GENERATE_LENGHT 3 // Length of separating bytes between generator source codes +#define BW_PACKAGE_SEPARATE_LUA_MODULE_LENGHT 3 // Length of separating bytes between module source codes -// Length of separating bytes json configuration of the bweas package -#define BW_PACKAGE_SEPARATE_JSON_BYTES_LENGHT 3 - -// Length of separating bytes between cache source codes -#define BW_PACKAGE_SEPARATE_LUA_CACHE_LENGHT 3 - -// Length of separating bytes between generator source codes -#define BW_PACKAGE_SEPARATE_LUA_GENERATE_LENGHT 3 - -// Maximum bweas packet size(5 mb) -#define MAX_SIZE_BW_PACKAGE 5 MB +#define MAX_SIZE_BW_PACKAGE 5 MB // Maximum bweas packet size(5 mb) namespace bweas { // Class defining bweas packages class bwpackage { public: - bwpackage(); + bwpackage() = default; public: // Data for creating a bweas package @@ -95,7 +79,7 @@ class bwpackage { cache_lua cache; std::vector generators; - module::module_mg::modules mds; + bwmodule_mg::modules modules; std::map custom_ext_fields_project; }; @@ -106,7 +90,7 @@ class bwpackage { std::string init(data_bw_package _data, bool is_create_pckg = 0); // Decompresses the read bweas packet, and also determines the correctness of its structure - void load(std::string raw_data_package); + void load(std::string_view raw_data_package); public: // Returns 1 - if the package is initialized (*package name is not non-zero), otherwise 0 @@ -117,11 +101,6 @@ class bwpackage { var::struct_sb::version bw_version; config cfg_package; - - private: - std::string path_to_package; - - static inline bool init_glob{0}; }; } // namespace bweas diff --git a/src/bs/bwtools.cpp b/src/bs/bwtools.cpp new file mode 100644 index 0000000..c6214b2 --- /dev/null +++ b/src/bs/bwtools.cpp @@ -0,0 +1,143 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#if defined(UNIX) +#include +#include +#endif + +using namespace bweas; + +std::vector bwtools::files; + +void bwtools::message(std::string_view str) { + fprintf(stdout, "%s\n", str.data()); +} +void bwtools::success(std::string_view str) { + fprintf(stdout, "\e[1;32m%s\e[0m\n", str.data()); +} +void bwtools::warning(std::string_view str_warn) { + fprintf(stderr, "\e[1;33m bweas warning: "); + fprintf(stderr, "%s\e[0m\n", str_warn.data()); +} +void bwtools::error(std::string_view str_err) { + fprintf(stderr, "\e[1;31m bweas error: "); + if (str_err.empty()) + fprintf(stderr, "%s\e[0m\n", std::strerror(errno)); + else + fprintf(stderr, "%s\e[0m\n", str_err.data()); +} +void bwtools::fatal(std::string_view str_err) { + fprintf(stderr, "\e[1;31m bweas fatal error: "); + if (str_err.empty()) + fprintf(stderr, "%s\e[0m\n", std::strerror(errno)); + else + fprintf(stderr, "%s\e[0m\n", str_err.data()); + +#ifdef WIN + ExitProcess(FATAL_ERROR); +#endif + exit(FATAL_ERROR); +} +std::string bwtools::get_time() { + auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + tm *time_now = std::localtime(&time); + + return std::to_string(time_now->tm_mon) + "." + std::to_string(time_now->tm_mday) + " " + + std::to_string(time_now->tm_hour) + ":" + std::to_string(time_now->tm_min); +} + +std::string bwtools::get_path_program() { +#if defined(WIN) + char buffer[MAX_PATH]; + GetModuleFileNameA(NULL, buffer, MAX_PATH); +#elif defined(UNIX) + char buffer[PATH_MAX]; + ssize_t count = readlink("/proc/self/exe", buffer, PATH_MAX); +#endif + std::string str(buffer); + str.erase(str.find_last_of("/\\"), str.size()); + + FATAL(); + return str; +} +std::string bwtools::get_current_path() { + return std::filesystem::current_path(); +} +bwtools::file_it bwtools::open_file(std::string_view name_file, file::mode_file::open mode) { + file_it it = get_iterator_file(name_file); + if (exist_file(it) && !(files.begin() + it)->file_opened) { + files[it].open(mode); + return it; + } + files.emplace_back(std::filesystem::absolute(name_file), mode); + + return files.size() - 1; +} +void bwtools::close_file(bwtools::file_it file) { + if (!exist_file(file)) + fatal("There are no files with this index."); + files.erase(files.begin() + file); +} +bool bwtools::exist_file(file_it file) { + if ((files.begin() + file) == files.end() || !(files.begin() + file)->file_opened) + return 0; + return 1; +} +bool bwtools::exist_file(std::string_view name_file) { + if (std::filesystem::exists(name_file)) + return 1; + return 0; +} +bwtools::file_it bwtools::get_iterator_file(std::string_view name_file) { + return std::distance(files.begin(), + std::find_if(files.begin(), files.end(), [name_file](const bwtools::file &file) { + return file.path_to == std::filesystem::absolute(name_file); + })); +} + +bwtools::file &bwtools::get_ref_file(file_it file) { + return *(files.begin() + file); +} + +std::string bwtools::read_file(file &file, file::mode_file::input mode) { + std::string data_file; + if (mode == file::mode_file::input::read_binary) { + u32t size_file; + file.stream.seekg(0, std::ios::end); + size_file = file.stream.tellg(); + file.stream.seekg(0, std::ios::beg); + data_file.resize(size_file); + file.stream.read(data_file.data(), size_file); + } + else { + std::string tmp; + while (std::getline(file.stream, tmp)) + data_file += tmp + "\n"; + } + + return data_file; +} +void bwtools::write_file(file &file, std::string_view buf, file::mode_file::output mode) { + if (mode == file::mode_file::output::write_binary) + file.stream.write(buf.data(), buf.size()); + else + file.stream << buf; +} + diff --git a/src/bs/bwtools.hpp b/src/bs/bwtools.hpp new file mode 100644 index 0000000..15d9722 --- /dev/null +++ b/src/bs/bwtools.hpp @@ -0,0 +1,179 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + +#ifndef _BWTOOLS__H_ +#define _BWTOOLS__H_ + +#include + +#include +#include +#include +#include +#include + +#ifndef _DEBUG +#define FATAL(str) \ + if (errno) \ + bwtools::fatal(str) + +#else +#define FATAL(str) \ + if (errno) \ + bwtools::fatal(std::string(__FILE__) + ":" + std::to_string(__LINE__) + " " + std::string(__func__) + "() " str) +#endif + +#define FATAL_ERROR 1 + +namespace bweas { +class bwtools; +extern bwtools _bwtools; +} // namespace bweas + +// A base class that implements many auxiliary functions +class bweas::bwtools { + public: + struct file { + struct mode_file { + private: + mode_file() = delete; + + public: + // mode of open + enum class open { + // open for read of binary + rb = 0, + // open for default reading + r, + // open for overwrite or create file with writing + w, + // open for writes to the end of the file + wa, + // open for overwrite or create file with writing of binary + wb, + // open for writes to the end of the file of binary + wba + }; + + // mode of reading + enum class input { + // read of binary + read_binary, + // default reading + read_default + }; + // mode of writing + enum class output { + // write of binary(all bytes) + write_binary, + + // default writing + write_default + }; + }; + + public: + file() = default; + file(const file &) = delete; + file &operator=(const file &) = delete; + file(file &&_file) noexcept { + if (_file.file_opened) + _file.stream.close(); + path_to = _file.path_to; + mode_open = _file.mode_open; + open(); + } + file(std::filesystem::path _path_to, mode_file::open _mode_open) : path_to(_path_to), mode_open(_mode_open) { + open(); + } + ~file() { + close(); + } + file &operator=(file &&_file) noexcept { + if (_file.file_opened) + _file.stream.close(); + path_to = _file.path_to; + mode_open = _file.mode_open; + open(); + + return *this; + } + + void open(mode_file::open _mode_open, std::filesystem::path _path_to = {}) { + path_to = _path_to; + mode_open = _mode_open; + open(); + } + + // Opens a file with the specified mode + void open() { + if (mode_open == mode_file::open::rb) + stream.open(path_to.string(), std::ios::in | std::ios::binary); + else if (mode_open == mode_file::open::r) + stream.open(path_to.string(), std::ios::in); + else if (mode_open == mode_file::open::w) + stream.open(path_to.string(), std::ios::out | std::ios::trunc); + else if (mode_open == mode_file::open::wb) + stream.open(path_to.string(), std::ios::out | std::ios::binary | std::ios::trunc); + else if (mode_open == mode_file::open::wba) + stream.open(path_to.string(), std::ios::out | std::ios::binary | std::ios::app); + else + stream.open(path_to.string(), std::ios::out | std::ios::app); + + if (stream.is_open()) + file_opened = 1; + } + + // Closes the file if the stream is open + void close() { + if (file_opened) { + stream.close(); + file_opened = 0; + } + } + + public: + std::fstream stream; + std::filesystem::path path_to; + mode_file::open mode_open; + bool file_opened{0}; + }; + + public: + using file_it = u32t; + + static void message(std::string_view str); + static void success(std::string_view str); + + static void warning(std::string_view str_warn); + static void error(std::string_view str_error = ""); + static void fatal(std::string_view str_error = ""); + + static std::string get_time(); + + static std::string get_path_program(); + static std::string get_current_path(); + + public: + static file_it open_file(std::string_view name_file, file::mode_file::open mode = file::mode_file::open::r); + static void close_file(file_it file); + + static bool exist_file(file_it file); + static bool exist_file(std::string_view name_file); + + static file_it get_iterator_file(std::string_view name_file); + static file &get_ref_file(file_it file); + + static std::string read_file(file &file, file::mode_file::input mode = file::mode_file::input::read_default); + static void write_file(file &file, std::string_view buf, + file::mode_file::output mode = file::mode_file::output::write_default); + + private: + static std::vector files; +}; + +#endif diff --git a/src/bs/bwtype.h b/src/bs/bwtype.h new file mode 100644 index 0000000..5e46053 --- /dev/null +++ b/src/bs/bwtype.h @@ -0,0 +1,18 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + +#ifndef BWTYPE__H_ +#define BWTYPE__H_ + +#include + +typedef ptrdiff_t i32t; +typedef size_t u32t; +typedef unsigned short u16t; +typedef unsigned char u8t; + +#endif diff --git a/src/bs/lang/expression.hpp b/src/bs/lang/expression.hpp index ba07575..f117d6d 100644 --- a/src/bs/lang/expression.hpp +++ b/src/bs/lang/expression.hpp @@ -8,12 +8,16 @@ #ifndef EXPRESSION__H #define EXPRESSION__H -#include "scope.hpp" -#include "token.hpp" - +#include +#include +#include #include -namespace aef_expr { +#include + +namespace var { +class scope; +} // list of parameters that the function can expect enum class param_type { @@ -21,12 +25,15 @@ enum class param_type { // this parameter tells semantic analysis that: // 1. the current function (most likely) is a declaring function // 2. it needs to check that the name that was passed as a parameter - // of this type does not exist in the symbol table of the global or external scope + // of this type does not exist in the symbol table of the global or + // external scope FUTURE_VAR_ID, - // this parameter tells the semantic parser that it does not need to worry about + // this parameter tells the semantic parser that it does not need to worry + // about // the issue of declaring the identifier; with this parameter it will - // not create a declaration of the symbol in the symbol table, and will not check whether it exists + // not create a declaration of the symbol in the symbol table, and will not + // check whether it exists NCHECK_VAR_ID, VAR_ID, @@ -53,143 +60,91 @@ enum class param_type { }; struct param { - param(param_type _param_t, std::string _default_val = "") : param_t(_param_t), default_val(_default_val) { + param(param_type _type, std::string_view _default_val = "") : type(_type), default_val(_default_val) { } - inline bool decl_default_val() { + inline bool decl_default_val() const { return !default_val.empty(); } - param_type param_t; + param_type type; std::string default_val; }; -struct subexpressions; +struct statement; +struct expression; + +using expressions = std::vector; +using statements = std::vector; // the notion of a function, which contains a reference // to the function itself, the parameters that it expects when called, // and two fields that define the call to this function -struct notion_func { - notion_func() = default; - explicit notion_func(void (*func)(const std::vector &, var::scope &), std::vector params) - : func_ref(func), expected_params(params) { +struct decl_func { + using func_t = std::function; + + public: + decl_func() = default; + explicit decl_func(std::string_view _name_func, func_t _func, std::vector _expected_params) + : name_func(_name_func), func(_func), expected_params(_expected_params) { } - using func_t = void (*)(const std::vector &, var::scope &); + public: + inline u32t count_default_param() const; - inline u32t count_default_param(); + public: + std::string name_func; - func_t func_ref; + func_t func; std::vector expected_params; - - // does the function declare anyone - // (if so, then the function will be called during semantic analysis) - bool is_declaration_var{0}; - - // whether to call a function in semantic parsing - // (provided so that certain functions that cannot declare - // anything can be called in semantic analysis) - bool only_with_semantic{0}; }; -// a structure that is a representation -// (notion) of a function -struct notion_expr_func { +// structure is a representation of a single function call +struct statement { + public: + statement() = default; + explicit statement(const decl_func *_expr_func, expressions _expr_s, u32t _line = 0, u32t _column = 0) + : expr_func(_expr_func), expr_s(_expr_s), line(_line), column(_column) { + } - // function call token - token_expr::token func_t; - notion_func func_n; -}; + public: + std::string get_location() const { + return "[" + std::to_string(line) + ":" + std::to_string(column) + "]"; + } -// structure is a representation of a single function call -struct expression { - inline bool execute_with_semantic_an(); + public: + const decl_func *expr_func; + expressions expr_s; - notion_expr_func expr_func; - std::vector sub_expr_s; + u32t line, column; }; // structure is a list of parameters passed // to the function when it is called -struct subexpressions { - // declaration of all possible parameter types - enum class type_subexpr { - INT_COMPARE, - STRING_ADD, - INT, +struct expression { + public: + enum class expression_t { + NUMBER = 0, STRING, ID, - KEYWORD_OP, - - SIZE_ENUM_TYPE_SUBEXPR + SIZE_ENUM_RET_TYPE_EXPR }; - enum class ret_type_subexpr { - INT, - STRING, - ID, - SIZE_ENUM_RET_TYPE_SUBEXPR - }; - subexpressions() = default; - explicit subexpressions(std::vector _token_of_subexpr, type_subexpr _subexpr_t) - : token_of_subexpr(_token_of_subexpr), subexpr_t(_subexpr_t) { + public: + expression() = default; + explicit expression(std::string_view _value, expression_t _type, u32t line = 0, u32t column = 0) + : value(_value), type(_type) { } - inline ret_type_subexpr returned_type_subexpr() const; - inline bool param_match_ret_type_subexpr(param_type) const; + public: + expression_t type; + std::string value; - // tokens of single parameter - std::vector token_of_subexpr; - type_subexpr subexpr_t; + u32t line, column; }; -// Determines the need to call this function in semantic analysis -inline bool expression::execute_with_semantic_an() { - return expr_func.func_n.is_declaration_var || expr_func.func_n.only_with_semantic; -} - -// Defines the return type (expected after semantic analysis) -inline subexpressions::ret_type_subexpr subexpressions::returned_type_subexpr() const { - if (subexpr_t == type_subexpr::INT || subexpr_t == type_subexpr::INT_COMPARE) - return ret_type_subexpr::INT; - else if (subexpr_t == type_subexpr::STRING || subexpr_t == type_subexpr::STRING_ADD) - return ret_type_subexpr::STRING; - else if (subexpr_t == type_subexpr::ID) - return ret_type_subexpr::ID; - else if (subexpr_t == type_subexpr::KEYWORD_OP) { - const auto &it = - std::find_if(this->token_of_subexpr.begin(), this->token_of_subexpr.end(), [](const token_expr::token &tk) { - return tk.token_t == token_expr::token_type::KW_OPERATOR && IS_BIBARY_KW_OP(tk.token_val); - }); - if (it == this->token_of_subexpr.end()) { - if (RET_INT_KW_OP(this->token_of_subexpr[0].token_val)) - return ret_type_subexpr::INT; - else if (RET_STR_KW_OP(this->token_of_subexpr[0].token_val)) - return ret_type_subexpr::STRING; - } - else if (RET_INT_KW_OP(it->token_val)) - return ret_type_subexpr::INT; - else if (RET_STR_KW_OP(it->token_val)) - return ret_type_subexpr::STRING; - } - return ret_type_subexpr::SIZE_ENUM_RET_TYPE_SUBEXPR; -} - -inline bool subexpressions::param_match_ret_type_subexpr(param_type _param) const { - ret_type_subexpr subexpr_rt = returned_type_subexpr(); - if ((subexpr_rt == ret_type_subexpr::ID && - (_param == param_type::FUTURE_VAR_ID || _param == param_type::NCHECK_VAR_ID || _param == param_type::VAR_ID || - _param == param_type::VAR_STRUCT_ID)) || - (subexpr_rt == ret_type_subexpr::INT && - (_param == param_type::LIT_NUM || _param == param_type::LNUM_OR_ID_VAR)) || - (subexpr_rt == ret_type_subexpr::STRING && - (_param == param_type::LIT_STR || _param == param_type::LSTR_OR_ID_VAR))) - return 1; - return 0; -} - -inline u32t notion_func::count_default_param() { +inline u32t decl_func::count_default_param() const { u32t count_dp = 0; for (const param &_param : expected_params) if (!_param.default_val.empty()) @@ -198,26 +153,55 @@ inline u32t notion_func::count_default_param() { return count_dp; } -static inline subexpressions::type_subexpr conv_param_type_to_subexpr_type(param_type _param) { +static inline expression::expression_t conv_param_type_to_expr_type(param_type _param) { if (_param == param_type::FUTURE_VAR_ID || _param == param_type::NCHECK_VAR_ID || _param == param_type::VAR_ID || _param == param_type::VAR_STRUCT_ID) - return subexpressions::type_subexpr::ID; + return expression::expression_t::ID; else if (_param == param_type::LIT_NUM || _param == param_type::LNUM_OR_ID_VAR) - return subexpressions::type_subexpr::INT; + return expression::expression_t::NUMBER; else if (_param == param_type::LIT_STR || _param == param_type::LSTR_OR_ID_VAR) - return subexpressions::type_subexpr::STRING; - return subexpressions::type_subexpr::SIZE_ENUM_TYPE_SUBEXPR; + return expression::expression_t::STRING; + return expression::expression_t::SIZE_ENUM_RET_TYPE_EXPR; } -static inline token_expr::token_type conv_param_type_to_token_type(param_type _param) { - if (_param == param_type::FUTURE_VAR_ID || _param == param_type::NCHECK_VAR_ID || _param == param_type::VAR_ID || - _param == param_type::VAR_STRUCT_ID) - return token_expr::token_type::ID; - else if (_param == param_type::LIT_NUM || _param == param_type::LNUM_OR_ID_VAR) - return token_expr::token_type::LITERAL; - else if (_param == param_type::LIT_STR || _param == param_type::LSTR_OR_ID_VAR) - return token_expr::token_type::LITERALS; - return token_expr::token_type::SIZE_ENUM_TOKEN_TYPE; + +static inline bool operator==(expression::expression_t e_type, param_type p_type) { + if (conv_param_type_to_expr_type(p_type) == e_type) + return true; + return false; +} + +static inline const char *get_string_expr_type(expression::expression_t type) { + if (type == expression::expression_t::NUMBER) + return "NUMBER"; + else if (type == expression::expression_t::STRING) + return "STRING"; + else if (type == expression::expression_t::ID) + return "ID"; + return "UNDEFINED"; } -} // namespace aef_expr +static inline param_type get_string_param_type(std::string_view str) { + if (str == "FUTURE_VAR_ID") + return param_type::FUTURE_VAR_ID; + else if (str == "VAR_ID") + return param_type::VAR_ID; + else if (str == "NCHECK_VAR") + return param_type::NCHECK_VAR_ID; + else if (str == "VAR_STRUCT_ID") + return param_type::VAR_STRUCT_ID; + else if (str == "ANY_VALUE_WITHOUT_FUTUREID_NEXT") + return param_type::ANY_VALUE_WITHOUT_FUTUREID_NEXT; + else if (str == "LIT_STR") + return param_type::LIT_STR; + else if (str == "LIT_NUM") + return param_type::LIT_NUM; + else if (str == "LSTR_OR_ID_VAR") + return param_type::LSTR_OR_ID_VAR; + else if (str == "LNUM_OR_ID_VAR") + return param_type::LSTR_OR_ID_VAR; + else if (str == "NEXT_TOO") + return param_type::NEXT_TOO; + else + return param_type::SIZE_ENUM_PARAMS; +} #endif diff --git a/src/bs/lang/interpreter.cpp b/src/bs/lang/interpreter.cpp index add47d8..c8412ee 100644 --- a/src/bs/lang/interpreter.cpp +++ b/src/bs/lang/interpreter.cpp @@ -1,128 +1,54 @@ #include "interpreter.hpp" -#include "static_linking_func.hpp" -using namespace interpreter; +static logger _log{"INTERPRETER[BWLANG]"}; -using mf = assistant::file::mode_file; -using file_it = assistant::file_it; +extern FILE *yyin; +extern int yyparse(void); -interpreter_exec::interpreter_exec() { - if (!init_glob) { - assist.add_err("RTT003", "It is impossible to find the structure"); - assist.add_err("RTT004", "Failed to open file"); - assist.add_err("RTT005", "Internal function error"); +extern var::scope *current_scope; +extern bweas::logger *log_bison; +extern statements stm_s; - init_glob = 1; - } -} +interpreter::interpreter(std::string_view name_file) : global_scope{_log}, smt_analyzer{_log} { + yyin = fopen(name_file.data(), "r"); + log_bison = &_log; + current_scope = &global_scope; -void interpreter_exec::set_config(config conf) { - interp_conf = conf; -} -void interpreter_exec::set_external_scope(var::scope *_external_scope) { - external_scope = _external_scope; + if (yyin == NULL) + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Not found file: " << name_file); } -void interpreter_exec::build_aef() { - file_it bweas_config = assist.open_file(interp_conf.filename_interp, mf::open::rb); - - parser.set_additional_const( - {{STR_KEYWORD_OP_CONST_RELEASE, token_expr::token(token_expr::token_type::LITERAL, "1")}, - {STR_KEYWORD_OP_CONST_DEBUG, token_expr::token(token_expr::token_type::LITERAL, "0")}, - {STR_KEYWORD_OP_CONST_TRUE, token_expr::token(token_expr::token_type::LITERAL, "1")}, - {STR_KEYWORD_OP_CONST_FALSE, token_expr::token(token_expr::token_type::LITERAL, "0")}}); - - lexer.set_symbols(assist.read_file(assist.get_ref_file(bweas_config), mf::input::read_binary)); - assist.close_file(bweas_config); - - global_scope.clear(); - - debug_init_time() - - smt_analyzer.load_external_func_table(external_func_table); -#if defined(WIN) - assist.safe_call_dll_func_begin(); -#endif - if (interp_conf.debug_output) { - debug_mark_time_func(lexer.analysis(), "lexer") - parser.set_tokens(lexer.get_tokens()); - debug_mark_time_func(parser.analysis(), "parser") - aef = parser.get_exprs(); - if (interp_conf.use_external_scope) { - debug_mark_time_func(smt_analyzer.analysis(aef, *external_scope), "semantic analyzer") - } - else { - debug_mark_time_func(smt_analyzer.analysis(aef, global_scope), "semantic analyzer") - } - } - else { - parser.set_tokens(lexer.analysis()); - aef = parser.analysis(); - - if (interp_conf.use_external_scope) - smt_analyzer.analysis(aef, *external_scope); - else - smt_analyzer.analysis(aef, global_scope); - } -#ifdef _WIN32 - assist.safe_call_dll_func_end(); -#endif +void interpreter::set_external_scope(var::scope *_external_scope) { + external_scope = _external_scope; + current_scope = &(*external_scope); } -void interpreter_exec::interpret() { -#if defined(WIN) - curr_expr = 0; - assist.safe_call_dll_func_begin(); - for (; curr_expr < aef.size(); ++curr_expr) { - if (aef[curr_expr].execute_with_semantic_an()) - continue; - aef[curr_expr].expr_func.func_n.func_ref(aef[curr_expr].sub_expr_s, global_scope); - assist.check_safe_call_dll_func(); - } - assist.safe_call_dll_func_end(); -#elif defined(UNIX) - curr_expr = 0; - for (; curr_expr < aef.size(); ++curr_expr) { - if (aef[curr_expr].execute_with_semantic_an()) - continue; - aef[curr_expr].expr_func.func_n.func_ref(aef[curr_expr].sub_expr_s, global_scope); - assist.check_safe_call_dl_func(); - } -#endif +void interpreter::interpret() { + yyparse(); + smt_analyzer.analysis(stm_s, *current_scope); } -std::vector interpreter_exec::export_targets() { +std::vector interpreter::export_targets() { const std::vector> &vec_targets_ref = global_scope.get_vector_variables_t(); std::vector targets; - for (u32t i = 0; i < vec_targets_ref.size(); ++i) { + for (u32t i = 0; i < vec_targets_ref.size(); ++i) targets.push_back(vec_targets_ref[i].second); - } return targets; } -var::scope &interpreter_exec::get_current_scope() { - if (interp_conf.use_external_scope) +var::scope &interpreter::get_current_scope() { + if (external_scope != &global_scope) return *external_scope; - return global_scope; + return *current_scope; } -void interpreter_exec::load_external_func(const semantic_an::table_func &tfuncs) { - std::vector tmp_w_smt_funcs; - for (auto &func : tfuncs) { - if (interp_conf.transmit_smt_name_func_with_smt && - (func.second.is_declaration_var || func.second.only_with_semantic)) - tmp_w_smt_funcs.push_back(func.first); - external_func_table[func.first] = func.second; - } - - if (interp_conf.transmit_smt_name_func_with_smt) - smt_analyzer.append_external_name_func_w_smt(tmp_w_smt_funcs); +void interpreter::create_function(const decl_func &func) { + current_scope->create_var(func.name_func, func); } - -void interpreter_exec::set_std_function(std::string name_token_func, aef_expr::notion_func::func_t func_ref, - std::vector expected_param) { - smt_analyzer.add_func_flink(name_token_func, func_ref, expected_param); +void interpreter::create_function(std::string_view name_func, decl_func::func_t func, + std::vector expected_params) { + current_scope->create_var(name_func.data(), decl_func{name_func, func, expected_params}); } diff --git a/src/bs/lang/interpreter.hpp b/src/bs/lang/interpreter.hpp index 4bd3e2e..f1081f5 100644 --- a/src/bs/lang/interpreter.hpp +++ b/src/bs/lang/interpreter.hpp @@ -1,96 +1,36 @@ #ifndef INTERPRETER__H #define INTERPRETER__H -#include "semantic_an.hpp" +#include -namespace interpreter { - -#define debug_init_time() clock_t beg; - -#define debug_mark_time_func(func, func_name) \ - beg = clock(); \ - func; \ - assist << std::string("Run time " func_name ": " + std::to_string((double)(clock() - beg) / CLOCKS_PER_SEC)); - -class realtime_excp : public ::bwexception::bweas_exception { - public: - realtime_excp(std::string _what_hp, std::string number_err) - : what_hp(_what_hp), bweas_exception("RTT" + number_err) { - } - ~realtime_excp() noexcept override final = default; - - public: - const char *what() const noexcept override final { - return what_hp.c_str(); - } - - private: - std::string what_hp; -}; - -class interpreter_exec { +class interpreter { public: - struct config { - // output: - // - tree after semanticanalyzer - // - run time every of components interpreter(lexer, parser...) - bool debug_output{0}; - - // whether to use external scope - bool use_external_scope{0}; + interpreter(std::string_view name_file); - // whether to pass the list of external functions that - // should be called in semantic analysis to semantic analysis - bool transmit_smt_name_func_with_smt{0}; + interpreter(interpreter &&) = delete; + interpreter(const interpreter &) = delete; + interpreter &operator=(interpreter &&) = delete; - std::string filename_interp; - }; + ~interpreter() = default; public: - interpreter_exec(); - - interpreter_exec(interpreter_exec &&) = delete; - interpreter_exec(const interpreter_exec &) = delete; - interpreter_exec &operator=(interpreter_exec &&) = delete; - - ~interpreter_exec() = default; - - public: - // Compiles an abstract expression of function - void build_aef(); - // Interpretation of functions (not declaring, and which are not // explicitly marked as called in the semantic analysis) void interpret(); - void set_config(config conf); void set_external_scope(var::scope *_external_scope); + var::scope &get_current_scope(); std::vector export_targets(); - var::scope &get_current_scope(); - - void load_external_func(const semantic_an::table_func &tfuncs); - void set_std_function(std::string name_token_func, aef_expr::notion_func::func_t func_ref, - std::vector expected_param); + void create_function(const decl_func &func); + void create_function(std::string_view name_func, decl_func::func_t func, std::vector expected_params); private: - static inline bool init_glob{0}; - - config interp_conf; - var::scope global_scope; - var::scope *external_scope{&global_scope}; - - lexer::lex_an lexer; - parser::pars_an parser; - semantic_an::semantic_analyzer smt_analyzer; - - parser::abstract_expr_func aef; - semantic_an::table_func external_func_table; + var::scope *external_scope = (var::scope *)&global_scope; - u32t curr_expr{0}; + semantic_analyzer smt_analyzer; }; -} // namespace interpreter #endif diff --git a/src/bs/lang/lexer.cpp b/src/bs/lang/lexer.cpp deleted file mode 100644 index c857408..0000000 --- a/src/bs/lang/lexer.cpp +++ /dev/null @@ -1,232 +0,0 @@ -#include "../../mdef.hpp" - -#include "lexer.hpp" - -using namespace lexer; -using namespace token_expr; - -lex_an::lex_an() { - if (!init_glob) { - init_glob = 1; - assist.add_err("LEX000", "The lexeme does not obey the rules of the grammar of the scripting language"); - } -} - -lex_an::lex_an(const std::string &_symbols) { - lex_an(); - set_symbols(_symbols); -} - -char lex_an::get() { - if (pos >= symbols.size()) - return '\0'; - return symbols[pos++]; -} - -char lex_an::peek() { - if (pos >= symbols.size()) - return '\0'; - return symbols[pos + 1]; -} - -bool lex_an::check_sym_valid_grammar(char ch) { - if (ch == '*' || ch == '/' || ch == '!' || ch == '-' || ch == '\'' || ch == '[' || ch == ']' || ch == '{' || - ch == '}') - return 0; - return 1; -} - -void lex_an::set_symbols(const std::string &_symbols) { - symbols = _symbols; -} -std::vector lex_an::get_tokens() { - return tokens; -} -void lex_an::clear_tokens() { - tokens.clear(); -} -void lex_an::set_keyword_ops(const std::vector &_keyword_ops) { - for (const auto &keyword_op : _keyword_ops) - keyword_ops.push_back(keyword_op); -} - -std::vector lex_an::analysis() { - std::string lexem; - token tmp_curr_token; - - bool literal = 0, num = 0, br = 0; - bool err_lexem = 0; - - bool expected_separate = 0; - - bool was_br = 0; - - bool lexer_option = 0; - bool comment = 0; - - bool separate_tk = 0; - - u32t count_line = 1; - u32t count_sym = 0; - - pos = 0; - - char ch; - while (ch = get()) { - ++count_sym; - if ((ch == ' ' || ch == '\n' || ch == '\r' | ch == '\t') && !br) { - if (err_lexem) - throw lexer_excp("\n(Line: " + std::to_string(count_line) + "; Symbols start pos: " + - std::to_string(count_sym - lexem.size()) + "): Lexem - \"" + lexem + "\"\n", - "000"); - - if (lexer_option && (ch == '\r' || ch == '\n')) { - if (lexem.empty()) - throw lexer_excp("\n(Line: " + std::to_string(count_line) + "; Symbols start pos: " + - std::to_string(count_sym - lexem.size()) + "): Lexem - \"" + lexem + "\"\n", - "000"); - if (lexem == "lexer_stop") - break; - else - throw lexer_excp("\n(Line: " + std::to_string(count_line) + "; Symbols start pos: " + - std::to_string(count_sym - lexem.size()) + "): Lexem - \"" + lexem + "\"\n", - "000"); - } - while (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t') { - if (ch == '\n') { - ++count_line; - count_sym = 1; - comment = 0; - } - else if (ch == '\0') - break; - ch = get(); - } - if (!lexem.empty()) - separate_tk = 1; - } - - if (ch == '#') { - if (!lexem.empty()) - throw lexer_excp("\n(Line: " + std::to_string(count_line) + "; Symbols start pos: " + - std::to_string(count_sym - lexem.size()) + "): Lexem - \"" + lexem + "\"\n", - "000"); - if (comment) - comment = 0; - else - comment = 1; - continue; - } - else if (comment) - continue; - else if (ch == '\"') { - if (!br) - br = 1; - else { - br = 0; - was_br = 1; - } - continue; - } - else if (ch == '@') { - if (!lexem.empty() || lexer_option) - throw lexer_excp("\n(Line: " + std::to_string(count_line) + "; Symbols start pos: " + - std::to_string(count_sym - lexem.size()) + "): Lexem - \"" + lexem + "\"\n", - "000"); - - lexer_option = 1; - continue; - } - else if ((ch == '(' || ch == ')' || ch == ',' || ch == '>' || ch == '<' || ch == '=' || ch == '+') && !br || - separate_tk) { - if (err_lexem) - throw lexer_excp("\n(Line: " + std::to_string(count_line) + "; Symbols start pos: " + - std::to_string(count_sym - lexem.size()) + "): Lexem - \"" + lexem + "\"\n", - "000"); - else if (separate_tk) { - if (ch == '(' || ch == ')' || ch == ',' || ch == '>' || ch == '<' || ch == '=' || ch == '+') - separate_tk = 0; - } - - tmp_curr_token.pos_beg_defined_sym = count_sym - lexem.size(); - tmp_curr_token.pos_defined_line = count_line; - if (!lexem.empty()) { - tmp_curr_token.token_val = lexem; - if (literal) { - if (was_br) { - tmp_curr_token.token_t = token_type::LITERALS; - tokens.push_back(tmp_curr_token); - - was_br = 0; - } - else { - if (std::atoll(tmp_curr_token.token_val.c_str()) > INT32_MAX) - throw lexer_excp("\n(Line: " + std::to_string(count_line) + - "; Symbols start pos: " + std::to_string(count_sym - lexem.size()) + - "): Lexem - \"" + lexem + "\"\n", - "000"); - tmp_curr_token.token_t = token_type::LITERAL; - tokens.push_back(tmp_curr_token); - } - } - else if (lexem == STR_KEYWORD_IF || lexem == STR_KEYWORD_ELSE || lexem == STR_KEYWORD_ENDIF) { - tmp_curr_token.token_t = token_type::KEYWORD; - tokens.push_back(tmp_curr_token); - } - else if (std::find(keyword_ops.begin(), keyword_ops.end(), lexem) != keyword_ops.end()) { - tmp_curr_token.token_t = token_type::KW_OPERATOR; - tokens.push_back(tmp_curr_token); - } - else { - tmp_curr_token.token_t = token_type::ID; - tokens.push_back(tmp_curr_token); - } - - tmp_curr_token.token_val.clear(); - lexem.clear(); - } - if (ch == '>' || ch == '<' || ch == '=' || ch == '+') { - tmp_curr_token.token_t = token_type::OPERATOR; - tmp_curr_token.token_val += ch; - tokens.push_back(tmp_curr_token); - tmp_curr_token.token_val.clear(); - } - else if (ch == '(' || ch == ')' || ch == ',') { - if (ch == '(') - tmp_curr_token.token_t = token_type::OPEN_BR; - else if (ch == ')') - tmp_curr_token.token_t = token_type::CLOSE_BR; - else if (ch == ',') - tmp_curr_token.token_t = token_type::COMMA; - tokens.push_back(tmp_curr_token); - } - num = 0, literal = 0; - - if (separate_tk) - separate_tk = 0; - else - continue; - } - else if (ch == '\\' && br) { - if (pos == symbols.size()) - throw lexer_excp("\n(Line: " + std::to_string(count_line) + "; Symbols start pos: " + - std::to_string(count_sym - lexem.size()) + "): Lexem - \"" + lexem + "\"\n", - "000"); - ch = get(); - } - if (lexem.empty() && (isdigit(ch) || br)) { - literal = 1; - num = 1; - } - if ((num && !isdigit(ch) && !br) || (!check_sym_valid_grammar(ch) && !br) || was_br) - err_lexem = 1; - lexem += ch; - } - - if (br) - throw lexer_excp("\n(Line: " + std::to_string(count_line) + "; Symbols start pos: " + - std::to_string(count_sym - lexem.size()) + "): Lexem - \"" + lexem + "\"\n", - "000"); - - return tokens; -} diff --git a/src/bs/lang/lexer.hpp b/src/bs/lang/lexer.hpp deleted file mode 100644 index 7194b1a..0000000 --- a/src/bs/lang/lexer.hpp +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef _LEXER__H -#define _LEXER__H - -#include "../tools/bwexception.hpp" -#include "token.hpp" - -#include -#include - -namespace lexer { - -class lexer_excp : public ::bwexception::bweas_exception { - public: - lexer_excp(std::string _what_hp, std::string number_err) : what_hp(_what_hp), bweas_exception("LEX" + number_err) { - } - ~lexer_excp() noexcept override final = default; - - public: - const char *what() const noexcept override final { - return what_hp.c_str(); - } - - private: - std::string what_hp; -}; - -class lex_an { - public: - lex_an(); - lex_an(const std::string &_symbols); - - lex_an(lex_an &&) = delete; - lex_an(const lex_an &) = delete; - lex_an &operator=(lex_an &&) = delete; - - ~lex_an() = default; - - public: - void set_symbols(const std::string &_symbols); - std::vector get_tokens(); - void clear_tokens(); - - void set_keyword_ops(const std::vector &keyword_ops); - - // lexical analysis - // ---------------- - // Creates tokens with type "token_type". - // Prohibits: - // 1. use of symbols: * / ! - ' \. - // 2. form mixed lexemes: "32ggtn5var". - // 3. form a literal greater than UINT_MAX32/2. - // --------------------------------------------- - // When the @ symbol is encountered, it begins to form a lexeme until the end of the line - // (until the sequence of characters \r\n or \n is found), this lexeme will be a special word for the lexer, - // which, depending on its value, will perform one or another action. - // Available special words: - // 1. lexer_stop - std::vector analysis(); - - private: - char get(); - char peek(); - - // Prohibits characters - bool check_sym_valid_grammar(char ch); - - private: - static inline bool init_glob{0}; - - std::vector tokens; - std::string symbols; - - std::vector keyword_ops{STR_KEYWORD_OP_EQUAL, STR_KEYWORD_OP_AND, STR_KEYWORD_OP_OR, - STR_KEYWORD_OP_NOT, STR_KEYWORD_OP_TSTR}; - - u32t pos{0}; -}; - -} // namespace lexer - -#endif \ No newline at end of file diff --git a/src/bs/lang/lexer.l b/src/bs/lang/lexer.l new file mode 100644 index 0000000..14a70cc --- /dev/null +++ b/src/bs/lang/lexer.l @@ -0,0 +1,81 @@ +%{ + +#include + +#include +#include +#include + +#include +#include + +#include "parser.hpp" + +#define YY_USER_ACTION \ + yylloc.first_line = yylloc.last_line; \ + yylloc.first_column = yylloc.last_column; \ + for(int i = 0; yytext[i] != '\0'; ++i) \ + if(yytext[i] == '\n') { \ + yylloc.last_line++; \ + yylloc.last_column = 0; \ + } \ + else \ + yylloc.last_column++; + +extern var::scope* current_scope; + +%} + +%option noyywrap +%option yylineno + +%% + +[ \t\n\r]+ { ; } + +"(" { return OPEN_BR; } +")" { return CLOSE_BR; } +"," { return COMMA; } +"+" { return PLUS; } +"-" { return MINUS; } +"*" { return MUL; } +"/" { return DIV; } + +[0-9]+ { yylval.number = std::stoi(yytext); return NUMBER; } + +\"[^"\\]+\" { + std::string str_tmp = yytext; + str_tmp.erase(0, 1).erase(str_tmp.size()-1, 1); + yylval.string = strdup(str_tmp.data()); + return STRING; + } +[a-zA-Z_][a-zA-Z0-9_]+ { + std::string str_tmp = yytext; + + if(str_tmp.find("VAR_") == 0){ + str_tmp.erase(0, 4); + yylval.string = strdup(str_tmp.data()); + return ID; + } + else{ + u32t type = current_scope->what_type(str_tmp); + if(type == 1){ + yylval.number = current_scope->get_var_value(str_tmp); + return NUMBER; + } + else if(type == 2){ + yylval.string = strdup(current_scope->get_var_value(str_tmp).data()); + return STRING; + } + + yylval.string = strdup(str_tmp.data()); + return ID; + } + } + +. { + printf("Undefined token: %s\n", yytext); + yyterminate(); + } + +%% diff --git a/src/bs/lang/parser.cpp b/src/bs/lang/parser.cpp deleted file mode 100644 index df4d053..0000000 --- a/src/bs/lang/parser.cpp +++ /dev/null @@ -1,332 +0,0 @@ -#include "../../mdef.hpp" - -#include "parser.hpp" - -using namespace aef_expr; -using namespace token_expr; -using namespace parser::utility; - -#define is_param(token) \ - (token.token_t == token_type::ID || token.token_t == token_type::LITERAL || \ - token.token_t == token_type::LITERALS || token.token_t == token_type::KW_OPERATOR) - -using namespace parser; - -pars_an::pars_an() { - if (!init_glob) { - init_glob = 1; - assist.add_err("PARS000", "The beginning of the expression must be a token of type \"ID\" or \"KEYWORD\""); - assist.add_err("PARS001", "After the start of the expression, a token is expected to begin enumerating " - "arguments with type \"SYMBOL\" and value \"(\""); - assist.add_err("PARS002", "Function arguments can only be tokens of type (\"ID\", \"LITERAL\" or \"LITERALS\" " - "with the possibility of switching on \"OPERATOR\") <- subexpression"); - assist.add_err("PARS003", "A token of type \"OPERATOR\" is expected"); - assist.add_err("PARS004", "A token of type \"ID\", \"LITERAL\" or \"LITERALS\" is expected"); - assist.add_err("PARS005", "A token with the type \"ID\", \"LITERAL\" or \"LITERALS\" is expected after a token " - "with the type \"OPERATOR\" or \"KW_OPERATOR\""); - assist.add_err("PARS006", "It is impossible to add two different tokens by type"); - assist.add_err("PARS007", "It is impossible to compare two different tokens by type"); - assist.add_err("PARS008", "It is impossible to add strings when comparing"); - assist.add_err("PARS009", "Arithmetic operations are prohibited"); - assist.add_err("PARS010", "Impossible to compare strings"); - assist.add_err("PARS011", "You cannot use operators together with operator keywords"); - assist.add_err("PARS012", "Keyword operator is nonbinary"); - } -} - -pars_an::pars_an(const std::vector &tk_s) { - pars_an(); - tokens = tk_s; -} - -void pars_an::set_tokens(const std::vector &tk_s) { - tokens = tk_s; - expr_s.clear(); -} - -void pars_an::set_additional_const(std::unordered_map addit_const) { - this->addit_const = addit_const; -} - -abstract_expr_func pars_an::get_exprs() { - return expr_s; -} -void pars_an::clear_aef() { - expr_s.clear(); -} -void pars_an::check_valid_subexpr_first_pass(const subexpressions &sub_expr) { - if (sub_expr.token_of_subexpr.empty()) - return; - - bool expected_op = 0, expr_with_op = 0; - bool expected_param_kw_op = 0; - - for (u32t i = 0; i < sub_expr.token_of_subexpr.size(); ++i) { - if (sub_expr.token_of_subexpr[i].token_t == token_type::ID || - sub_expr.token_of_subexpr[i].token_t == token_type::LITERAL || - sub_expr.token_of_subexpr[i].token_t == token_type::LITERALS) { - if (expected_op) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[i]), "003"); - else if (expected_param_kw_op) - expected_param_kw_op = 0; - expected_op = 1; - } - else if (sub_expr.token_of_subexpr[i].token_t == token_type::KW_OPERATOR) { - if (expr_with_op) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[i]), "011"); - else if (expected_op) { - if (!IS_BIBARY_KW_OP(sub_expr.token_of_subexpr[i].token_val)) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[i]), "012"); - expected_op = 0; - } - expected_param_kw_op = 1; - } - else if (sub_expr.token_of_subexpr[i].token_t == token_type::OPERATOR) { - if (!expected_op || expected_param_kw_op) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[i]), "004"); - expected_op = 0; - expr_with_op = 1; - continue; - } - } - if ((!expected_op && - sub_expr.token_of_subexpr[sub_expr.token_of_subexpr.size() - 1].token_t == token_type::OPERATOR) || - (expected_param_kw_op && - addit_const.find(sub_expr.token_of_subexpr[sub_expr.token_of_subexpr.size() - 1].token_val) == - addit_const.end())) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[sub_expr.token_of_subexpr.size() - 1]), "005"); -} -void pars_an::check_valid_subexpr_second_pass(subexpressions &sub_expr) { - if (sub_expr.token_of_subexpr.empty()) - return; - - bool str_type_expr = 0, num_type_expr = 0, id_type_expr = 0; - bool operator_plus = 0, operator_compare = 0, keyword_op = 0; - - for (u32t i = 0; i < sub_expr.token_of_subexpr.size(); ++i) { - current_token: - if (sub_expr.token_of_subexpr[i].token_t == token_type::LITERALS) { - if (num_type_expr) { - if (operator_plus) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[i]), "006"); - else if (operator_compare) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[i]), "007"); - } - str_type_expr = 1; - } - else if (sub_expr.token_of_subexpr[i].token_t == token_type::LITERAL) { - if (str_type_expr) { - if (operator_plus) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[i]), "006"); - else if (operator_compare) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[i]), "007"); - } - num_type_expr = 1; - } - else if (sub_expr.token_of_subexpr[i].token_t == token_type::ID) { - const auto &it_keyword_ops = addit_const.find(sub_expr.token_of_subexpr[i].token_val); - if (it_keyword_ops != addit_const.end()) { - sub_expr.token_of_subexpr[i] = it_keyword_ops->second; - goto current_token; - } - id_type_expr = 1; - } - else if (sub_expr.token_of_subexpr[i].token_t == token_type::OPERATOR && - sub_expr.token_of_subexpr[i].token_val == "+") { - if (operator_compare) - if (str_type_expr) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[i]), "008"); - else if (num_type_expr) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[i]), "009"); - operator_plus = 1; - } - else if (sub_expr.token_of_subexpr[i].token_t == token_type::OPERATOR && - (sub_expr.token_of_subexpr[i].token_val == ">" || sub_expr.token_of_subexpr[i].token_val == "<" || - sub_expr.token_of_subexpr[i].token_val == "=")) { - if (operator_plus) - if (str_type_expr) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[i]), "010"); - else if (num_type_expr) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[i]), "009"); - operator_compare = 1; - } - else if (sub_expr.token_of_subexpr[i].token_t == token_type::KW_OPERATOR) - keyword_op = 1; - } - if (operator_compare) { - sub_expr.subexpr_t = subexpressions::type_subexpr::INT_COMPARE; - try_parse_subexpr(sub_expr); - } - else if (operator_plus) { - sub_expr.subexpr_t = subexpressions::type_subexpr::STRING_ADD; - try_parse_subexpr(sub_expr); - } - else if (keyword_op) - sub_expr.subexpr_t = subexpressions::type_subexpr::KEYWORD_OP; - else if (num_type_expr) - sub_expr.subexpr_t = subexpressions::type_subexpr::INT; - else if (str_type_expr) - sub_expr.subexpr_t = subexpressions::type_subexpr::STRING; - else if (id_type_expr) - sub_expr.subexpr_t = subexpressions::type_subexpr::ID; -} - -void pars_an::try_parse_subexpr(subexpressions &sub_expr) { - subexpressions parse_subexpr; - subexpressions const_parse_subexpr, tmp_parse_subexpr; - if (sub_expr.subexpr_t == subexpressions::type_subexpr::INT_COMPARE) { - for (u32t i = 0; i < sub_expr.token_of_subexpr.size(); ++i) { - if (sub_expr.token_of_subexpr[i].token_t == token_type::ID) { - for (u32t j = 0; j < const_parse_subexpr.token_of_subexpr.size(); ++j) { - parse_subexpr.token_of_subexpr.push_back(const_parse_subexpr.token_of_subexpr[j]); - } - parse_subexpr.token_of_subexpr.push_back(sub_expr.token_of_subexpr[i]); - const_parse_subexpr.token_of_subexpr.clear(); - continue; - } - else if (sub_expr.token_of_subexpr[i].token_t == token_type::LITERALS) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[i]), "010"); - if (const_parse_subexpr.token_of_subexpr.size() == 0 && - (sub_expr.token_of_subexpr[i].token_t == token_type::OPERATOR || - (i == sub_expr.token_of_subexpr.size() - 1))) - parse_subexpr.token_of_subexpr.push_back(sub_expr.token_of_subexpr[i]); - else - const_parse_subexpr.token_of_subexpr.push_back(sub_expr.token_of_subexpr[i]); - if (const_parse_subexpr.token_of_subexpr.size() == 3) { - bool condition = 0; - switch (const_parse_subexpr.token_of_subexpr[1].token_val[0]) { - case '>': - if (std::stoi(const_parse_subexpr.token_of_subexpr[0].token_val.c_str()) > - std::stoi(const_parse_subexpr.token_of_subexpr[2].token_val.c_str())) - condition = 1; - break; - case '<': - if (std::stoi(const_parse_subexpr.token_of_subexpr[0].token_val.c_str()) < - std::stoi(const_parse_subexpr.token_of_subexpr[2].token_val.c_str())) - condition = 1; - break; - case '=': - if (std::stoi(const_parse_subexpr.token_of_subexpr[0].token_val.c_str()) == - std::stoi(const_parse_subexpr.token_of_subexpr[2].token_val.c_str())) - condition = 1; - break; - } - tmp_parse_subexpr = const_parse_subexpr; - const_parse_subexpr.token_of_subexpr.clear(); - if (condition) - const_parse_subexpr.token_of_subexpr.push_back( - token(token_type::LITERAL, "1", tmp_parse_subexpr.token_of_subexpr[0].pos_defined_line, - tmp_parse_subexpr.token_of_subexpr[0].pos_beg_defined_sym)); - else - const_parse_subexpr.token_of_subexpr.push_back( - token(token_type::LITERAL, "0", tmp_parse_subexpr.token_of_subexpr[0].pos_defined_line, - tmp_parse_subexpr.token_of_subexpr[0].pos_beg_defined_sym)); - } - } - } - else if (sub_expr.subexpr_t == subexpressions::type_subexpr::STRING_ADD) { - for (u32t i = 0; i < sub_expr.token_of_subexpr.size(); ++i) { - if (sub_expr.token_of_subexpr[i].token_t == token_type::ID) { - for (u32t j = 0; j < const_parse_subexpr.token_of_subexpr.size(); ++j) { - parse_subexpr.token_of_subexpr.push_back(const_parse_subexpr.token_of_subexpr[j]); - } - parse_subexpr.token_of_subexpr.push_back(sub_expr.token_of_subexpr[i]); - const_parse_subexpr.token_of_subexpr.clear(); - continue; - } - else if (sub_expr.token_of_subexpr[i].token_t == token_type::LITERAL) - throw parser_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[i]), "009"); - if (const_parse_subexpr.token_of_subexpr.size() == 0 && - (sub_expr.token_of_subexpr[i].token_t == token_type::OPERATOR || - (i == sub_expr.token_of_subexpr.size() - 1))) - parse_subexpr.token_of_subexpr.push_back(sub_expr.token_of_subexpr[i]); - else - const_parse_subexpr.token_of_subexpr.push_back(sub_expr.token_of_subexpr[i]); - if (const_parse_subexpr.token_of_subexpr.size() == 3) { - tmp_parse_subexpr = const_parse_subexpr; - const_parse_subexpr.token_of_subexpr.clear(); - const_parse_subexpr.token_of_subexpr.push_back(token( - token_type::LITERALS, - tmp_parse_subexpr.token_of_subexpr[0].token_val + tmp_parse_subexpr.token_of_subexpr[2].token_val, - tmp_parse_subexpr.token_of_subexpr[0].pos_defined_line, - tmp_parse_subexpr.token_of_subexpr[0].pos_beg_defined_sym)); - } - } - } - else - return; - - for (u32t j = 0; j < const_parse_subexpr.token_of_subexpr.size(); ++j) { - parse_subexpr.token_of_subexpr.push_back(const_parse_subexpr.token_of_subexpr[j]); - } - if (parse_subexpr.token_of_subexpr.size() == 1) { - if (parse_subexpr.token_of_subexpr[0].token_t == token_type::LITERAL) - parse_subexpr.subexpr_t = subexpressions::type_subexpr::INT; - else - parse_subexpr.subexpr_t = subexpressions::type_subexpr::STRING; - } - else - parse_subexpr.subexpr_t = sub_expr.subexpr_t; - sub_expr = parse_subexpr; -} - -abstract_expr_func &pars_an::analysis() { - bool start_expr = 1, func_param_curr = 0; - - expression curr_expr; - subexpressions curr_sub_expr; - - for (u32t i = 0; i < tokens.size(); ++i) { - if (start_expr) { - if (tokens[i].token_t != token_type::ID && tokens[i].token_t != token_type::KEYWORD) - throw parser_excp(build_pos_tokenb_str(tokens[i]), "000"); - curr_expr.expr_func.func_t = tokens[i]; - start_expr = 0; - } - else { - if (!func_param_curr) { - if (tokens[i].token_t == token_type::OPEN_BR) { - func_param_curr = 1; - continue; - } - throw parser_excp(build_pos_tokenb_str(tokens[i]), "001"); - } - else if (func_param_curr && tokens[i].token_t == token_type::COMMA) { - if (!is_param(tokens[i - 1])) - throw parser_excp(build_pos_tokenb_str(tokens[i]), "004"); - check_valid_subexpr_first_pass(curr_sub_expr); - check_valid_subexpr_second_pass(curr_sub_expr); - curr_expr.sub_expr_s.push_back(curr_sub_expr); - curr_sub_expr.token_of_subexpr.clear(); - continue; - } - else if (func_param_curr && tokens[i].token_t == token_type::CLOSE_BR) { - if (!is_param(tokens[i - 1])) { - if (tokens[i - 1].token_t != token_type::OPEN_BR) - throw parser_excp(build_pos_tokenb_str(tokens[i]), "004"); - goto start_expr_func; - } - check_valid_subexpr_first_pass(curr_sub_expr); - check_valid_subexpr_second_pass(curr_sub_expr); - curr_expr.sub_expr_s.push_back(curr_sub_expr); - curr_sub_expr.token_of_subexpr.clear(); - - start_expr_func: - func_param_curr = 0; - start_expr = 1; - - expr_s.push_back(curr_expr); - curr_expr.sub_expr_s.clear(); - - continue; - } - else if (func_param_curr && tokens[i].token_t != token_type::ID && - tokens[i].token_t != token_type::LITERAL && tokens[i].token_t != token_type::LITERALS && - tokens[i].token_t != token_type::OPERATOR && tokens[i].token_t != token_type::KW_OPERATOR) - throw parser_excp(build_pos_tokenb_str(tokens[i]), "002"); - curr_sub_expr.token_of_subexpr.push_back(tokens[i]); - } - } - - return expr_s; -} \ No newline at end of file diff --git a/src/bs/lang/parser.hpp b/src/bs/lang/parser.hpp deleted file mode 100644 index 6339095..0000000 --- a/src/bs/lang/parser.hpp +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef _PARSER__H -#define _PARSER__H - -#include "expression.hpp" -#include "lexer.hpp" -#include "scope.hpp" - -#include -#include - -namespace parser { - -// abstract expression of functions -using abstract_expr_func = std::vector; - -// auxiliary functions for translating some structural types into an info string - -namespace utility { - -extern std::string type_token_str(token_expr::token_type token_t); -extern std::string type_ret_subexpr(aef_expr::subexpressions::ret_type_subexpr subexpr_ret_t); -extern std::string build_pos_tokenb_str(const token_expr::token &tk); -extern std::string build_pos_subexpr_str(const aef_expr::subexpressions &sub_expr); -extern std::string type_sybexpr_str(aef_expr::subexpressions::type_subexpr sub_expr_t); -extern std::string tree_build_visually_str(const abstract_expr_func &aef); - -extern aef_expr::param_type type_param_in_str(std::string str); - -} // namespace utility - -class parser_excp : public ::bwexception::bweas_exception { - public: - parser_excp(std::string _what_hp, std::string number_err) - : what_hp(_what_hp), bweas_exception("PARS" + number_err) { - } - ~parser_excp() noexcept override final = default; - - public: - const char *what() const noexcept override final { - return what_hp.c_str(); - } - - private: - std::string what_hp; -}; - -class pars_an { - public: - pars_an(); - pars_an(const std::vector &tk_s); - - pars_an(pars_an &&) = delete; - pars_an(const pars_an &) = delete; - - pars_an &operator=(pars_an &&) = delete; - - ~pars_an() = default; - - public: - void set_tokens(const std::vector &tk_s); - void set_additional_const(std::unordered_map addit_const); - - abstract_expr_func get_exprs(); - void clear_aef(); - - // Parsing - // ------- - // ID(PARAM1, PARAM2, ...) - // - // ----------------------- - // It requires that a certain sequence of tokens begin with a keyword or function identifier, - // that the enumeration of parameters begins with the token "(" and ends with ")", - // when enumerating parameters, the separator is used "," - abstract_expr_func &analysis(); - - private: - // Checks the correctness of the sequence of tokens in the current parameter - void check_valid_subexpr_first_pass(const aef_expr::subexpressions &sub_expr); - - // Checks the syntactic correctness of the scripting language capabilities (sets rules), - // and determines the syntactic type of the parameter. - // It prohibits: - // 1. Arithmetic operations - // 2. Comparing strings or two different tokens by type (Number and String) - void check_valid_subexpr_second_pass(aef_expr::subexpressions &sub_expr); - - // Tries to convert separate sequences of tokens into one - void try_parse_subexpr(aef_expr::subexpressions &sub_expr); - - private: - static inline bool init_glob{0}; - - std::vector tokens; - abstract_expr_func expr_s; - - std::unordered_map addit_const; -}; - -} // namespace parser - -#endif \ No newline at end of file diff --git a/src/bs/lang/parser.y b/src/bs/lang/parser.y new file mode 100644 index 0000000..8fea7c9 --- /dev/null +++ b/src/bs/lang/parser.y @@ -0,0 +1,132 @@ +%{ + +#include +#include + +#include + +#define YYLLOC_UPDATE_GLOBAL_LOC(loc) last_line = loc.last_line; last_column = loc.last_column; + +bweas::logger *log_bison; +var::scope* current_scope; + +statements stm_s; +expressions current_params; // Current statement expressions +expression::expression_t expr_t_tmp; // Current expression type + +int last_line = 0, last_column = 0; + +extern int yylex(void); +void yyerror(const char* str){ + printf("Error: %s\n", str); +} + +void init_param(char* value){ + current_params.emplace_back(value, expr_t_tmp, last_line, last_column); + free(value); +} + +void init_statement(const decl_func* dfunc){ + stm_s.emplace_back(dfunc, current_params, last_line, last_column); + current_params.clear(); +} + +std::string get_current_loc(){ + return "[" + std::to_string(last_line) + ":" + std::to_string(last_column) + "]"; +} +%} + +%locations + +%union { + i32t number; + char* string; +} + +%token OPEN_BR +%token CLOSE_BR +%token COMMA +%token PLUS MINUS MUL DIV + +%token NUMBER STRING ID + +%left PLUS MINUS +%left MUL DIV + +%type NUMBER num_term num_expr +%type STRING ID str_term str_expr param + +%% + +statement: + | statement ID OPEN_BR params CLOSE_BR { //printf("---Statement %s(%s,%s,%s)---\n", $2, current_params[0].value.c_str(), current_params[1].value.c_str(), current_params[2].value.c_str()); + if(current_scope->what_type($2) != 10){ + (*log_bison) << bwtools::error << (log_message(log_type::error) << "A variable is expected which is a reference to the function: " << $2); + YYERROR; + } + init_statement(¤t_scope->get_var_value($2)); + } + | error { + (*log_bison) << bwtools::fatal << (log_message(log_type::fatal) << "[" << @1.last_line << ":" << @1.last_column << "]: syntax error: Invalid statement"); + YYABORT; + } +; + +params: param { + YYLLOC_UPDATE_GLOBAL_LOC(@$) + init_param($1); + } + | params COMMA param { + YYLLOC_UPDATE_GLOBAL_LOC(@$) + init_param($3); + } +; +param: ID { + $$ = $1; + expr_t_tmp = expression::expression_t::ID; + } + | num_expr { + $$ = (char*)malloc(sizeof(char)*10); + sprintf($$, "%d", $1); + expr_t_tmp = expression::expression_t::NUMBER; + } + | str_expr { + $$ = $1; + expr_t_tmp = expression::expression_t::STRING; + } + | error { + (*log_bison) << bwtools::fatal << (log_message(log_type::fatal) << "[" << @1.last_line << ":" << @1.last_column << "]: syntax error: Invalid parameter definition"); + YYABORT; + } +; + +num_expr: OPEN_BR num_expr CLOSE_BR { $$ = $2; } + | num_expr PLUS num_expr { $$ = $1 + $3; } + | num_expr MINUS num_expr { $$ = $1 - $3; } + | num_expr MUL num_expr { $$ = $1 * $3; } + | num_expr DIV num_expr { + if($3 == 0){ + (*log_bison) << bwtools::fatal << (log_message(log_type::fatal) << "Division by zero"); + YYERROR; + } + $$ = $1 / $3; + } + | num_term { $$ = $1; } +; + +str_expr: str_expr PLUS str_term { + $$ = strdup((std::string($1)+ $3).data()); + free($1); + free($3); + } + | str_term { $$ = $1; } +; + +num_term: NUMBER { $$ = $1; } +; + +str_term: STRING { $$ = $1; } +; + +%% + diff --git a/src/bs/lang/parser_utility.cpp b/src/bs/lang/parser_utility.cpp deleted file mode 100644 index c9672c7..0000000 --- a/src/bs/lang/parser_utility.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include "parser.hpp" - -using namespace aef_expr; -using namespace token_expr; - -std::string parser::utility::type_token_str(token_type token_t) { - switch (token_t) { - case token_type::KEYWORD: - return "KEYWORD"; - case token_type::ID: - return "ID"; - case token_type::LITERAL: - return "LITERAL"; - case token_type::LITERALS: - return "LITERALS"; - case token_type::OPERATOR: - return "OPERATOR"; - case token_type::OPEN_BR: - return "OPEN_BR"; - case token_type::CLOSE_BR: - return "CLOSE_BR"; - case token_type::COMMA: - return "COMMA"; - case token_type::KW_OPERATOR: - return "KW_OPERATOR"; - default: - return "UNDEF"; - } -} - -std::string parser::utility::type_ret_subexpr(aef_expr::subexpressions::ret_type_subexpr subexpr_ret_t) { - switch (subexpr_ret_t) { - case subexpressions::ret_type_subexpr::INT: - return "NUMBER"; - case subexpressions::ret_type_subexpr::STRING: - return "STRING"; - case subexpressions::ret_type_subexpr::ID: - return "VAR ID"; - break; - default: - return ""; - } -} - -std::string parser::utility::build_pos_tokenb_str(const token &tk) { - std::string tmp_str; - if (tk.pos_defined_line == -1) - tmp_str += "\n(unknown position): "; - else { - tmp_str += "\n(Line: " + std::to_string(tk.pos_defined_line); - if (tk.pos_beg_defined_sym == -1) - tmp_str += "): "; - else - tmp_str += "; Symbols start pos: " + std::to_string(tk.pos_beg_defined_sym) + "): "; - } - if (!tk.token_val.empty()) - return tmp_str + "Type token - " + type_token_str(tk.token_t) + "; Token value - \"" + tk.token_val + "\"\n"; - return tmp_str + "Type token - " + type_token_str(tk.token_t) + "\n"; -} -std::string parser::utility::build_pos_subexpr_str(const subexpressions &sub_expr) { - std::string str; - str = "\n(Line: " + std::to_string(sub_expr.token_of_subexpr[0].pos_defined_line) + - "; Symbols start pos: " + std::to_string(sub_expr.token_of_subexpr[0].pos_beg_defined_sym) + - "): Expression(" + type_ret_subexpr(sub_expr.returned_type_subexpr()) + ") <"; - for (u32t i = 0; i < sub_expr.token_of_subexpr.size(); ++i) { - str += sub_expr.token_of_subexpr[i].token_val; - if (i < sub_expr.token_of_subexpr.size() - 1) - str += " "; - } - str += ">\n"; - return str; -} -std::string parser::utility::type_sybexpr_str(subexpressions::type_subexpr sub_expr_t) { - switch (sub_expr_t) { - case subexpressions::type_subexpr::ID: - return "ID"; - case subexpressions::type_subexpr::INT: - return "INT"; - case subexpressions::type_subexpr::STRING: - return "STRING"; - case subexpressions::type_subexpr::INT_COMPARE: - return "INT_COMPARE"; - case subexpressions::type_subexpr::STRING_ADD: - return "STRING_ADD"; - default: - return ""; - } -} -std::string parser::utility::tree_build_visually_str(const abstract_expr_func &aef) { - std::stringstream tree_visible; - for (u32t i = 0; i < aef.size(); ++i) { - tree_visible << "EXPRESSION:\n"; - tree_visible << " |TOKEN FUNC: " << "TYPE TOKEN: " << type_token_str(aef[i].expr_func.func_t.token_t) - << "; LEXEM: " << aef[i].expr_func.func_t.token_val << '\n'; - for (u32t j = 0; j < aef[i].sub_expr_s.size(); ++j) { - tree_visible << " | | " << j << " SUBEXPRESSION " << type_sybexpr_str(aef[i].sub_expr_s[j].subexpr_t) - << ": \n"; - std::string value_expr; - for (u32t k = 0; k < aef[i].sub_expr_s[j].token_of_subexpr.size(); ++k) { - tree_visible << " | | | -> " << type_token_str(aef[i].sub_expr_s[j].token_of_subexpr[k].token_t) - << "(" << aef[i].sub_expr_s[j].token_of_subexpr[k].token_val << ")\n"; - value_expr += aef[i].sub_expr_s[j].token_of_subexpr[k].token_val; - } - tree_visible << " | | SOURCE: " << value_expr << '\n'; - tree_visible << " | ------------------" << '\n'; - value_expr.clear(); - } - } - return tree_visible.str(); -} -param_type parser::utility::type_param_in_str(std::string str) { - if (str == "FUTURE_VAR_ID") - return param_type::FUTURE_VAR_ID; - else if (str == "VAR_ID") - return param_type::VAR_ID; - else if (str == "NCHECK_VAR") - return param_type::NCHECK_VAR_ID; - else if (str == "VAR_STRUCT_ID") - return param_type::VAR_STRUCT_ID; - else if (str == "ANY_VALUE_WITHOUT_FUTUREID_NEXT") - return param_type::ANY_VALUE_WITHOUT_FUTUREID_NEXT; - else if (str == "LIT_STR") - return param_type::LIT_STR; - else if (str == "LIT_NUM") - return param_type::LIT_NUM; - else if (str == "LSTR_OR_ID_VAR") - return param_type::LSTR_OR_ID_VAR; - else if (str == "LNUM_OR_ID_VAR") - return param_type::LSTR_OR_ID_VAR; - else if (str == "NEXT_TOO") - return param_type::NEXT_TOO; - else - return param_type::SIZE_ENUM_PARAMS; -} diff --git a/src/bs/lang/scope.hpp b/src/bs/lang/scope.hpp index 8a176ab..e076a76 100644 --- a/src/bs/lang/scope.hpp +++ b/src/bs/lang/scope.hpp @@ -1,16 +1,21 @@ #ifndef _SCOPE__H #define _SCOPE__H -#include "../../kernel/high_level/bwtype.h" - -#include "../tools/bwexception.hpp" -#include "../tools/call_cmd.hpp" -#include "static_struct.hpp" -#include "var.hpp" - #include #include +#include + +#include +#include +#include + +#include + +extern std::string get_current_loc(); + +using namespace bweas; + namespace var { inline std::string type_var_to_str(u32t ind) { @@ -32,30 +37,18 @@ inline std::string type_var_to_str(u32t ind) { return "call component"; else if (ind == 9) return "global external args"; + else if (ind == 10) + return "function"; return "undef"; } -class scope_excp : public ::bwexception::bweas_exception { - public: - scope_excp(std::string _what_hp, std::string number_err) : what_hp(_what_hp), bweas_exception("SCOP" + number_err) { - } - ~scope_excp() noexcept override final = default; - - public: - const char *what() const noexcept override final { - return what_hp.c_str(); - } - - private: - std::string what_hp; -}; - class scope { public: - inline scope(); + scope(bweas::logger &__log) : _log(__log) { + } inline scope(const scope &) = default; - inline scope(scope &&) = default; + inline scope(scope &&) = default; ~scope() = default; @@ -72,23 +65,26 @@ class scope { inline void clear(); - // 1 - int - // 2 - string - // 3 - vector - // 4 - vector - // 5 - project - // 6 - target - // 7 - template command - // 8 - call component - // 9 - global external args - // 0 - undefined + // 1 - int + // 2 - string + // 3 - vector + // 4 - vector + // 5 - project + // 6 - target + // 7 - template command + // 8 - call component + // 9 - global external args + // 10 - function + // 0 - undefined inline u32t what_type(std::string name_var); public: - tools::call_cmd_manager call_cmd; + call_cmd_manager call_cmd; private: - static inline bool init_glob{0}; + logger &_log; + + var::datatype_var funcs_v; var::datatype_var int_v; var::datatype_var str_v; @@ -102,61 +98,50 @@ class scope { var::datatype_var> global_ext_args_v; }; -inline scope::scope() { - if (!init_glob) { - init_glob = 1; - assist.add_err("SCOP000", "The variable does not exist"); - assist.add_err("SCOP001", "The variable has already been created(does exist)"); - assist.add_err("SCOP002", "Unknown data type"); - } -} - template inline T &scope::create_var(std::string name_var, T val) { if constexpr (std::is_same_v) { - if (int_v.create_var(name_var, val)) - throw scope_excp("int(" + std::to_string(val) + ") <- " + name_var, "001"); - return int_v.get_val_ref(name_var); + if (!int_v.create_var(name_var, val)) + return int_v.get_val_ref(name_var); } else if constexpr (std::is_same_v) { - if (str_v.create_var(name_var, val)) - throw scope_excp("string(" + val + ") <- " + name_var, "001"); - return str_v.get_val_ref(name_var); + if (!str_v.create_var(name_var, val)) + return str_v.get_val_ref(name_var); } else if constexpr (std::is_same_v) { - if (prj_v.create_var(name_var, val)) - throw scope_excp("project(" + val.name_project + ") <- " + name_var, "001"); - return prj_v.get_val_ref(name_var); + if (!prj_v.create_var(name_var, val)) + return prj_v.get_val_ref(name_var); } else if constexpr (std::is_same_v) { - if (trg_v.create_var(name_var, val)) - throw scope_excp("target(" + val.name_target + ") <- " + name_var, "001"); - return trg_v.get_val_ref(name_var); + if (!trg_v.create_var(name_var, val)) + return trg_v.get_val_ref(name_var); } else if constexpr (std::is_same_v>) { - if (vec_int_v.create_var(name_var, val)) - throw scope_excp("vector(" + std::to_string(val[0]) + ", ..." + ") <- " + name_var, "001"); - return vec_int_v.get_val_ref(name_var); + if (!vec_int_v.create_var(name_var, val)) + return vec_int_v.get_val_ref(name_var); } else if constexpr (std::is_same_v>) { - if (vec_str_v.create_var(name_var, val)) - throw scope_excp("vector(" + val[0] + ", ..." + ") <- " + name_var, "001"); - return vec_str_v.get_val_ref(name_var); + if (!vec_str_v.create_var(name_var, val)) + return vec_str_v.get_val_ref(name_var); } else if constexpr (std::is_same_v) { - if (tcmd_v.create_var(name_var, val)) - throw scope_excp("template_command(" + val.name + ", ..." + ") <- " + name_var, "001"); - return tcmd_v.get_val_ref(name_var); + if (!tcmd_v.create_var(name_var, val)) + return tcmd_v.get_val_ref(name_var); } else if constexpr (std::is_same_v) { - if (ccmp_v.create_var(name_var, val)) - throw scope_excp("call_component(" + val.name + ", ..." + ") <- " + name_var, "001"); - return ccmp_v.get_val_ref(name_var); + if (!ccmp_v.create_var(name_var, val)) + return ccmp_v.get_val_ref(name_var); } else if constexpr (std::is_same_v>) { - if (global_ext_args_v.create_var(name_var, val)) - throw scope_excp("global_external_args(" + val.first + ", ..." + ") <- " + name_var, "001"); - return global_ext_args_v.get_val_ref(name_var); + if (!global_ext_args_v.create_var(name_var, val)) + return global_ext_args_v.get_val_ref(name_var); } + else if constexpr (std::is_same_v) { + if (!funcs_v.create_var(name_var, val)) + return funcs_v.get_val_ref(name_var); + } + + (_log << bwtools::fatal) << (log_message(log_type::fatal) + << get_current_loc() << ": The " << name_var << " variable already exists"); } template inline bool scope::try_create_var(std::string name_var, T val) { @@ -179,95 +164,84 @@ template inline bool scope::try_create_var(std::string name_var, T creates = ccmp_v.create_var(name_var, val); else if constexpr (std::is_same_v>) creates = global_ext_args_v.create_var(name_var, val); + else if constexpr (std::is_same_v) + creates = funcs_v.create_var(name_var, val); return !creates; } template inline void scope::delete_var(std::string name_var) { - if constexpr (std::is_same_v) { - if (int_v.delete_var(name_var)) - throw scope_excp("int() <- " + name_var, "000"); - } - else if constexpr (std::is_same_v) { - if (str_v.delete_var(name_var)) - throw scope_excp("string() <- " + name_var, "000"); - } - else if constexpr (std::is_same_v) { - if (prj_v.delete_var(name_var)) - throw scope_excp("project() <- " + name_var, "000"); - } - else if constexpr (std::is_same_v) { - if (trg_v.delete_var(name_var)) - throw scope_excp("target() <- " + name_var, "000"); - } - else if constexpr (std::is_same_v>) { - if (vec_int_v.delete_var(name_var)) - throw scope_excp("vector() <- " + name_var, "000"); - } - else if constexpr (std::is_same_v>) { - if (vec_str_v.delete_var(name_var)) - throw scope_excp("vector() <- " + name_var, "000"); - } - else if constexpr (std::is_same_v) { - if (tcmd_v.delete_var(name_var)) - throw scope_excp("template_command() <- " + name_var, "000"); - } - else if constexpr (std::is_same_v) { - if (ccmp_v.delete_var(name_var)) - throw scope_excp("call_component() <- " + name_var, "000"); - } - else if constexpr (std::is_same_v>) { - if (global_ext_args_v.delete_var(name_var)) - throw scope_excp("global_external_args() <- " + name_var, "000"); - } + bool err_handling = 0; + + if constexpr (std::is_same_v) + err_handling = int_v.delete_var(name_var); + else if constexpr (std::is_same_v) + err_handling = str_v.delete_var(name_var); + else if constexpr (std::is_same_v) + err_handling = prj_v.delete_var(name_var); + else if constexpr (std::is_same_v) + err_handling = trg_v.delete_var(name_var); + else if constexpr (std::is_same_v>) + err_handling = vec_int_v.delete_var(name_var); + else if constexpr (std::is_same_v>) + err_handling = vec_str_v.delete_var(name_var); + else if constexpr (std::is_same_v) + err_handling = tcmd_v.delete_var(name_var); + else if constexpr (std::is_same_v) + err_handling = ccmp_v.delete_var(name_var); + else if constexpr (std::is_same_v>) + err_handling = global_ext_args_v.delete_var(name_var); + else if constexpr (std::is_same_v) + err_handling = funcs_v.delete_var(name_var); + + if (err_handling) + (_log << bwtools::error) << (log_message(log_type::error) << "The " << name_var << " variable does not exist"); } template inline T &scope::get_var_value(std::string name_var) { if constexpr (std::is_same_v) { - if (!int_v.is_exist_var(name_var)) - throw scope_excp("int() <- " + name_var, "000"); - return int_v.get_val_ref(name_var); + if (int_v.is_exist_var(name_var)) + return int_v.get_val_ref(name_var); } else if constexpr (std::is_same_v) { - if (!str_v.is_exist_var(name_var)) - throw scope_excp("string() <- " + name_var, "000"); - return str_v.get_val_ref(name_var); + if (str_v.is_exist_var(name_var)) + return str_v.get_val_ref(name_var); } else if constexpr (std::is_same_v) { - if (!prj_v.is_exist_var(name_var)) - throw scope_excp("project() <- " + name_var, "000"); - return prj_v.get_val_ref(name_var); + if (prj_v.is_exist_var(name_var)) + return prj_v.get_val_ref(name_var); } else if constexpr (std::is_same_v) { - if (!trg_v.is_exist_var(name_var)) - throw scope_excp("target() <- " + name_var, "000"); - return trg_v.get_val_ref(name_var); + if (trg_v.is_exist_var(name_var)) + return trg_v.get_val_ref(name_var); } else if constexpr (std::is_same_v>) { - if (!vec_int_v.is_exist_var(name_var)) - throw scope_excp("vector() <- " + name_var, "000"); - return vec_int_v.get_val_ref(name_var); + if (vec_int_v.is_exist_var(name_var)) + return vec_int_v.get_val_ref(name_var); } else if constexpr (std::is_same_v>) { - if (!vec_str_v.is_exist_var(name_var)) - throw scope_excp("vector() <- " + name_var, "000"); - return vec_str_v.get_val_ref(name_var); + if (vec_str_v.is_exist_var(name_var)) + return vec_str_v.get_val_ref(name_var); } else if constexpr (std::is_same_v) { - if (!tcmd_v.is_exist_var(name_var)) - throw scope_excp("template_command() <- " + name_var, "000"); - return tcmd_v.get_val_ref(name_var); + if (tcmd_v.is_exist_var(name_var)) + return tcmd_v.get_val_ref(name_var); } else if constexpr (std::is_same_v) { - if (!ccmp_v.is_exist_var(name_var)) - throw scope_excp("call_component() <- " + name_var, "000"); - return ccmp_v.get_val_ref(name_var); + if (ccmp_v.is_exist_var(name_var)) + return ccmp_v.get_val_ref(name_var); } else if constexpr (std::is_same_v>) { - if (!global_ext_args_v.is_exist_var(name_var)) - throw scope_excp("global_external_args() <- " + name_var, "000"); - return global_ext_args_v.get_val_ref(name_var); + if (global_ext_args_v.is_exist_var(name_var)) + return global_ext_args_v.get_val_ref(name_var); + } + else if constexpr (std::is_same_v) { + if (funcs_v.is_exist_var(name_var)) + return funcs_v.get_val_ref(name_var); } + + (_log << bwtools::fatal) << (log_message(log_type::fatal) + << get_current_loc() << ": The " << name_var << " variable does not exist"); } template inline std::vector> &scope::get_vector_variables_t() { @@ -289,12 +263,15 @@ template inline std::vector> &scope::get_ return ccmp_v.get_vector_variables(); else if constexpr (std::is_same_v>) return global_ext_args_v.get_vector_variables(); + else if constexpr (std::is_same_v) + return funcs_v.get_vector_variables(); } inline bool scope::is_exist(std::string name_var) { if (int_v.is_exist_var(name_var) || str_v.is_exist_var(name_var) || vec_int_v.is_exist_var(name_var) || vec_str_v.is_exist_var(name_var) || prj_v.is_exist_var(name_var) || trg_v.is_exist_var(name_var) || - tcmd_v.is_exist_var(name_var) || ccmp_v.is_exist_var(name_var) || global_ext_args_v.is_exist_var(name_var)) + tcmd_v.is_exist_var(name_var) || ccmp_v.is_exist_var(name_var) || global_ext_args_v.is_exist_var(name_var) || + funcs_v.is_exist_var(name_var)) return 1; return 0; } @@ -317,6 +294,8 @@ inline u32t scope::what_type(std::string name_var) { return 8; else if (global_ext_args_v.is_exist_var(name_var)) return 9; + else if (funcs_v.is_exist_var(name_var)) + return 10; else return 0; } @@ -331,6 +310,7 @@ inline void scope::clear() { tcmd_v.clear(); ccmp_v.clear(); global_ext_args_v.clear(); + funcs_v.clear(); } } // namespace var diff --git a/src/bs/lang/semantic_an.cpp b/src/bs/lang/semantic_an.cpp index 5e8e0a4..f22ce12 100644 --- a/src/bs/lang/semantic_an.cpp +++ b/src/bs/lang/semantic_an.cpp @@ -1,251 +1,193 @@ -#include "../../mdef.hpp" - #include "semantic_an.hpp" -#include - -using namespace parser; -using namespace parser::utility; -using namespace aef_expr; -using namespace semantic_an; - -semantic_analyzer::semantic_analyzer() { - if (!init_glob) { - init_glob = 1; - assist.add_err("SMT000", "The function symbol was not found when creating the symbol table"); - assist.add_err("SMT001", "The function values passed do not correspond to the expected ones"); - assist.add_err("SMT002", "Incorrect definition of function parameter types was observed"); - assist.add_err("SMT003", "When going through the aef, at one of the stages of " - "semantic analysis, an undefined error was noticed"); - assist.add_err("SMT004", "There is no variable with the expected type"); - assist.add_err("SMT005", "Arithmetic operations are prohibited at the external level"); - assist.add_err("SMT006", "It's not possible to compare non-numeric values"); - assist.add_err("SMT007", "It's not possible to use a structural variable in the set command"); - assist.add_err("SMT008", "It's impossible to determine the type of a non-existent variable"); - assist.add_err("SMT009", "Undefined error, it's impossible to determine the type of token"); - assist.add_err("SMT010", "A new symbol was expected"); - assist.add_err("SMT011", "Expected an existing symbol"); - assist.add_err("SMT012", "Another type of expression was expected"); - assist.add_err("SMT013", "The expected keyword was endif"); - assist.add_err("SMT014", "The endif keyword is only expected after the if or else keyword"); - assist.add_err("SMT015", "The expected keyword was if"); - assist.add_err("SMT016", "Keyword cannot be called"); - assist.add_err("SMT017", "The specified keyword operator is binary"); - assist.add_err("SMT018", "Undefined operands for the keyword operator"); - - assist.add_err("SMT-RT001", "An existing character was expected when " - "accessed during semantic analysis"); - assist.add_err("SMT-RT002", "The number of arguments has been exceeded"); - assist.add_err("SMT-RT003", "The type of the identifier does not match the types of parameters"); - assist.add_err("SMT-RT004", "Internal error of the declared function"); - } - - add_func_flink("if", NULL, {param_type::LNUM_OR_ID_VAR}); - add_func_flink("else", NULL, {}); - add_func_flink("endif", NULL, {}); +#define NOT_MATCHING_W_PARAMETERS "The function values passed do not correspond to the expected ones." +#define EXPECTED_NEW_SYMBOL "A new symbol was expected." +#define EXPECTED_EXIST_SYMBOL "Expected an existing symbol." +#define EXPECTED_ANOTHER_EXPR_TYPE "Another type of expression was expected." +#define IMPOSSIBLE_DETERMINE_TYPE_VAR "It's impossible to determine the type of a non-existent variable." +#define NOT_EXIST_VAR_W_EXPECTED_TYPE "There is no variable with the expected type." +#define EXPECTED_IF "The expected keyword was if" +#define EXPECTED_ENDIF "The expected keyword was endif" +#define INVALID_USAGE_ENDIF "The endif keyword is only expected after the if or else keyword" + +#define STR_KEYWORD_IF "if" +#define STR_KEYWORD_ELSE "else" +#define STR_KEYWORD_ENDIF "endif" + +semantic_analyzer::semantic_analyzer(logger &__log) : _log(__log) { } -void semantic_analyzer::analysis(abstract_expr_func &expr_s, var::scope &global_scope) { - smt_zero_pass(expr_s); - smt_first_pass(expr_s); - smt_second_pass(expr_s, global_scope); -} +void semantic_analyzer::analysis(statements &stm_s, var::scope ¤t_scope) { + current_scope.create_var(STR_KEYWORD_IF, decl_func(STR_KEYWORD_IF, NULL, {param_type::LNUM_OR_ID_VAR})); + current_scope.create_var(STR_KEYWORD_ELSE, decl_func(STR_KEYWORD_ELSE, NULL, {})); + current_scope.create_var(STR_KEYWORD_ENDIF, decl_func(STR_KEYWORD_ENDIF, NULL, {})); -void semantic_analyzer::load_external_func_table(const table_func ¬ion_external_func) { - this->notion_external_func = notion_external_func; + smt_first_pass(stm_s, current_scope); + smt_second_pass(stm_s, current_scope); } -void semantic_analyzer::append_external_name_func_w_smt(const std::vector &list_name_func) { - for (u32t i = 0; i < list_name_func.size(); ++i) { - name_func_with_semantic_an.push_back(list_name_func[i]); - } -} - -void semantic_analyzer::add_func_flink(std::string name_token_func, aef_expr::notion_func::func_t func_ref, - std::vector _expected_param) { - notion_func nfunc; - nfunc.func_ref = func_ref; - nfunc.expected_params = _expected_param; - defining_call_func(name_token_func, nfunc); - - std::pair n_link_func_spec = {name_token_func, nfunc}; - - notion_all_func.insert(n_link_func_spec); -} - -void semantic_analyzer::smt_zero_pass(const abstract_expr_func &expr_s) { - for (u32t i = 0; i < expr_s.size(); ++i) { - if (notion_all_func.find(expr_s[i].expr_func.func_t.token_val) != notion_all_func.end()) - continue; - if (notion_external_func.find(expr_s[i].expr_func.func_t.token_val) != notion_external_func.end()) { - std::pair n_link_func_spec = { - expr_s[i].expr_func.func_t.token_val, notion_external_func[expr_s[i].expr_func.func_t.token_val]}; - defining_call_func(n_link_func_spec.first, n_link_func_spec.second); - notion_all_func.insert(n_link_func_spec); - } - else - throw semantic_excp(build_pos_tokenb_str(expr_s[i].expr_func.func_t), "000"); - } -} - -void semantic_analyzer::smt_first_pass(abstract_expr_func &expr_s) { - for (u32t i = 0; i < expr_s.size(); ++i) { - expr_s[i].expr_func.func_n = notion_all_func[expr_s[i].expr_func.func_t.token_val]; - if (expr_s[i].expr_func.func_n.expected_params.size() != expr_s[i].sub_expr_s.size()) { - if (expr_s[i].expr_func.func_n.expected_params.size() != 0 && - expr_s[i] - .expr_func.func_n.expected_params[expr_s[i].expr_func.func_n.expected_params.size() - 1] - .param_t == param_type::NEXT_TOO && - (expr_s[i].expr_func.func_n.expected_params.size() - 1 == expr_s[i].sub_expr_s.size() || - expr_s[i].expr_func.func_n.expected_params.size() < expr_s[i].sub_expr_s.size()) || - (expr_s[i].expr_func.func_n.expected_params.size() - expr_s[i].sub_expr_s.size() != 0 && - expr_s[i].expr_func.func_n.expected_params.size() - expr_s[i].sub_expr_s.size() <= - expr_s[i].expr_func.func_n.count_default_param())) +void semantic_analyzer::smt_first_pass(statements &st_s, var::scope ¤t_scope) { + for (u32t i = 0; i < st_s.size(); ++i) { + if (st_s[i].expr_func->expected_params.size() != st_s[i].expr_s.size()) { + if (st_s[i].expr_func->expected_params.size() != 0 && + st_s[i].expr_func->expected_params[st_s[i].expr_func->expected_params.size() - 1].type == + param_type::NEXT_TOO && + (st_s[i].expr_func->expected_params.size() - 1 == st_s[i].expr_s.size() || + st_s[i].expr_func->expected_params.size() < st_s[i].expr_s.size()) || + (st_s[i].expr_func->expected_params.size() - st_s[i].expr_s.size() != 0 && + st_s[i].expr_func->expected_params.size() - st_s[i].expr_s.size() <= + st_s[i].expr_func->count_default_param())) goto check_valid_exp_type; - throw semantic_excp(build_pos_tokenb_str(expr_s[i].expr_func.func_t), "001"); + _log << bwtools::fatal + << (log_message(log_type::fatal) << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS); } - else if (expr_s[i].sub_expr_s.size() == 0) + else if (st_s[i].expr_s.size() == 0) continue; check_valid_exp_type: for (u32t j = 0, current_expected_param = 0; - j < expr_s[i].sub_expr_s.size() || - current_expected_param < expr_s[i].expr_func.func_n.expected_params.size(); + j < st_s[i].expr_s.size() || current_expected_param < st_s[i].expr_func->expected_params.size(); ++j, ++current_expected_param) { - if (expr_s[i].expr_func.func_n.expected_params[current_expected_param].decl_default_val()) { - if (j >= expr_s[i].sub_expr_s.size() || - !expr_s[i].sub_expr_s[j].param_match_ret_type_subexpr( - expr_s[i].expr_func.func_n.expected_params[current_expected_param].param_t)) { - expr_s[i].sub_expr_s.emplace( - expr_s[i].sub_expr_s.begin() + current_expected_param, - std::vector{token_expr::token{ - conv_param_type_to_token_type( - expr_s[i].expr_func.func_n.expected_params[current_expected_param].param_t), - expr_s[i].expr_func.func_n.expected_params[current_expected_param].default_val, 0, 0}}, - conv_param_type_to_subexpr_type( - expr_s[i].expr_func.func_n.expected_params[current_expected_param].param_t)); + if (st_s[i].expr_func->expected_params[current_expected_param].decl_default_val()) { + if (j >= st_s[i].expr_s.size() || + !(st_s[i].expr_s[j].type == st_s[i].expr_func->expected_params[current_expected_param].type)) { + st_s[i].expr_s.emplace(st_s[i].expr_s.begin() + current_expected_param, + expression{ + st_s[i].expr_func->expected_params[current_expected_param].default_val, + conv_param_type_to_expr_type( + st_s[i].expr_func->expected_params[current_expected_param].type), + }); continue; } } - else if (j >= expr_s[i].sub_expr_s.size()) + else if (j >= st_s[i].expr_s.size()) continue; - if ((expr_s[i].expr_func.func_n.expected_params[current_expected_param].param_t == - param_type::FUTURE_VAR_ID || - expr_s[i].expr_func.func_n.expected_params[current_expected_param].param_t == param_type::VAR_ID || - expr_s[i].expr_func.func_n.expected_params[current_expected_param].param_t == - param_type::NCHECK_VAR_ID || - expr_s[i].expr_func.func_n.expected_params[current_expected_param].param_t == - param_type::VAR_STRUCT_ID) && - expr_s[i].sub_expr_s[j].subexpr_t != subexpressions::type_subexpr::ID) - throw semantic_excp(build_pos_subexpr_str(expr_s[i].sub_expr_s[j]) + " Expected: [VAR ID]\n", "001"); - else if (expr_s[i].expr_func.func_n.expected_params[current_expected_param].param_t == - param_type::NEXT_TOO) { + if ((st_s[i].expr_func->expected_params[current_expected_param].type == param_type::FUTURE_VAR_ID || + st_s[i].expr_func->expected_params[current_expected_param].type == param_type::VAR_ID || + st_s[i].expr_func->expected_params[current_expected_param].type == param_type::NCHECK_VAR_ID || + st_s[i].expr_func->expected_params[current_expected_param].type == param_type::VAR_STRUCT_ID) && + st_s[i].expr_s[j].type != expression::expression_t::ID) + _log << bwtools::fatal + << (log_message(log_type::fatal) << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS + << " Expected: [VAR ID] - " << st_s[i].expr_s[j].value); + else if (st_s[i].expr_func->expected_params[current_expected_param].type == param_type::NEXT_TOO) { if (current_expected_param == 0 || - current_expected_param != expr_s[i].expr_func.func_n.expected_params.size() - 1) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].expr_func.func_t), "002"); - for (u32t b = j; b < expr_s[i].sub_expr_s.size(); ++b) { - if ((expr_s[i].expr_func.func_n.expected_params[current_expected_param - 1].param_t == + current_expected_param != st_s[i].expr_func->expected_params.size() - 1) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " + << "Incorrect definition of function parameter types was observed Expected: [VAR ID] - " + << st_s[i].expr_s[j].value); + for (u32t b = j; b < st_s[i].expr_s.size(); ++b) { + if ((st_s[i].expr_func->expected_params[current_expected_param - 1].type == param_type::FUTURE_VAR_ID || - expr_s[i].expr_func.func_n.expected_params[current_expected_param - 1].param_t == - param_type::VAR_ID || - expr_s[i].expr_func.func_n.expected_params[current_expected_param - 1].param_t == + st_s[i].expr_func->expected_params[current_expected_param - 1].type == param_type::VAR_ID || + st_s[i].expr_func->expected_params[current_expected_param - 1].type == param_type::VAR_STRUCT_ID) && - expr_s[i].sub_expr_s[b].subexpr_t != subexpressions::type_subexpr::ID) - throw semantic_excp(build_pos_subexpr_str(expr_s[i].sub_expr_s[b]) + " Expected: [VAR ID]\n", - "001"); - else if (expr_s[i].expr_func.func_n.expected_params[current_expected_param - 1].param_t == + st_s[i].expr_s[b].type != expression::expression_t::ID) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS + << " Expected: [VAR ID] - " << st_s[i].expr_s[b].value); + else if (st_s[i].expr_func->expected_params[current_expected_param - 1].type == param_type::ANY_VALUE_WITHOUT_FUTUREID_NEXT) { - if (expr_s[i].sub_expr_s[j - 1].token_of_subexpr[0].token_t == - token_expr::token_type::LITERAL && - expr_s[i].sub_expr_s[b].returned_type_subexpr() != subexpressions::ret_type_subexpr::INT && - expr_s[i].sub_expr_s[b].subexpr_t != subexpressions::type_subexpr::ID) - throw semantic_excp(build_pos_subexpr_str(expr_s[i].sub_expr_s[b]) + - " Expected: [NUMBER] or VAR ID->[NUMBER]\n", - "001"); - else if (expr_s[i].sub_expr_s[j - 1].token_of_subexpr[0].token_t == - token_expr::token_type::LITERALS && - expr_s[i].sub_expr_s[b].returned_type_subexpr() != - subexpressions::ret_type_subexpr::STRING && - expr_s[i].sub_expr_s[b].subexpr_t != subexpressions::type_subexpr::ID) - throw semantic_excp(build_pos_subexpr_str(expr_s[i].sub_expr_s[b]) + - " Expected: [STRING] or [VAR ID->[STRING]]\n", - "001"); + if (st_s[i].expr_s[j - 1].type == expression::expression_t::NUMBER && + st_s[i].expr_s[b].type != expression::expression_t::NUMBER && + st_s[i].expr_s[b].type != expression::expression_t::ID) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS + << " Expected: [NUMBER] or VAR ID->[NUMBER] - " << st_s[i].expr_s[b].value); + else if (st_s[i].expr_s[j - 1].type == expression::expression_t::STRING && + st_s[i].expr_s[b].type != expression::expression_t::STRING && + st_s[i].expr_s[b].type != expression::expression_t::ID) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS + << " Expected: [STRING] or [VAR ID->[STRING]] - " << st_s[i].expr_s[b].value); } - else if (expr_s[i].expr_func.func_n.expected_params[current_expected_param - 1].param_t == + else if (st_s[i].expr_func->expected_params[current_expected_param - 1].type == param_type::LIT_STR && - expr_s[i].sub_expr_s[b].returned_type_subexpr() != - subexpressions::ret_type_subexpr::STRING) - throw semantic_excp(build_pos_subexpr_str(expr_s[i].sub_expr_s[b]) + " Expected: [STRING]\n", - "001"); - else if (expr_s[i].expr_func.func_n.expected_params[current_expected_param - 1].param_t == + st_s[i].expr_s[b].type != expression::expression_t::STRING) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS + << " Expected: [STRING] - " << st_s[i].expr_s[b].value); + else if (st_s[i].expr_func->expected_params[current_expected_param - 1].type == param_type::LIT_NUM && - expr_s[i].sub_expr_s[b].returned_type_subexpr() != subexpressions::ret_type_subexpr::INT) - throw semantic_excp(build_pos_subexpr_str(expr_s[i].sub_expr_s[b]) + " Expected: [NUMBER]\n", - "001"); - else if (expr_s[i].expr_func.func_n.expected_params[current_expected_param - 1].param_t == + st_s[i].expr_s[b].type != expression::expression_t::NUMBER) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS + << " Expected: [NUMBER] - " << st_s[i].expr_s[b].value); + else if (st_s[i].expr_func->expected_params[current_expected_param - 1].type == param_type::LSTR_OR_ID_VAR && - expr_s[i].sub_expr_s[b].returned_type_subexpr() != - subexpressions::ret_type_subexpr::STRING && - expr_s[i].sub_expr_s[b].subexpr_t != subexpressions::type_subexpr::ID) - throw semantic_excp(build_pos_subexpr_str(expr_s[i].sub_expr_s[b]) + - " Expected: [STRING] OR [VAR ID]\n", - "001"); - else if (expr_s[i].expr_func.func_n.expected_params[current_expected_param - 1].param_t == + st_s[i].expr_s[b].type != expression::expression_t::STRING && + st_s[i].expr_s[b].type != expression::expression_t::ID) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS + << " Expected: [STRING] or [VAR ID->[STRING]] - " << st_s[i].expr_s[b].value); + else if (st_s[i].expr_func->expected_params[current_expected_param - 1].type == param_type::LNUM_OR_ID_VAR && - expr_s[i].sub_expr_s[b].returned_type_subexpr() != subexpressions::ret_type_subexpr::INT && - expr_s[i].sub_expr_s[b].subexpr_t != subexpressions::type_subexpr::ID) - throw semantic_excp(build_pos_subexpr_str(expr_s[i].sub_expr_s[b]) + - " Expected: [NUMBER] OR [VAR ID]\n", - "001"); + st_s[i].expr_s[b].type != expression::expression_t::NUMBER && + st_s[i].expr_s[b].type != expression::expression_t::ID) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS + << " Expected: [NUMBER] or VAR ID->[NUMBER] - " << st_s[i].expr_s[b].value); } break; } - else if (expr_s[i].expr_func.func_n.expected_params[current_expected_param].param_t == + else if (st_s[i].expr_func->expected_params[current_expected_param].type == param_type::ANY_VALUE_WITHOUT_FUTUREID_NEXT && - expr_s[i].sub_expr_s[j].returned_type_subexpr() != subexpressions::ret_type_subexpr::STRING && - expr_s[i].sub_expr_s[j].returned_type_subexpr() != subexpressions::ret_type_subexpr::INT && - expr_s[i].sub_expr_s[j].subexpr_t != subexpressions::type_subexpr::ID) - throw semantic_excp(build_pos_subexpr_str(expr_s[i].sub_expr_s[j]) + - " Expected: [STRING] OR [NUMBER] OR [VAR ID]\n", - "001"); - else if (expr_s[i].expr_func.func_n.expected_params[current_expected_param].param_t == - param_type::LIT_STR && - expr_s[i].sub_expr_s[j].returned_type_subexpr() != subexpressions::ret_type_subexpr::STRING) - throw semantic_excp(build_pos_subexpr_str(expr_s[i].sub_expr_s[j]) + " Expected: [STRING]\n", "001"); - else if (expr_s[i].expr_func.func_n.expected_params[current_expected_param].param_t == - param_type::LIT_NUM && - expr_s[i].sub_expr_s[j].returned_type_subexpr() != subexpressions::ret_type_subexpr::INT) - throw semantic_excp(build_pos_subexpr_str(expr_s[i].sub_expr_s[j]) + " Expected: [NUMBER]\n", "001"); - else if (expr_s[i].expr_func.func_n.expected_params[current_expected_param].param_t == - param_type::LSTR_OR_ID_VAR && - expr_s[i].sub_expr_s[j].returned_type_subexpr() != subexpressions::ret_type_subexpr::STRING && - expr_s[i].sub_expr_s[j].subexpr_t != subexpressions::type_subexpr::ID) - throw semantic_excp( - build_pos_subexpr_str(expr_s[i].sub_expr_s[j]) + " Expected: [STRING] OR [VAR ID]\n", "001"); - else if (expr_s[i].expr_func.func_n.expected_params[current_expected_param].param_t == - param_type::LNUM_OR_ID_VAR && - expr_s[i].sub_expr_s[j].returned_type_subexpr() != subexpressions::ret_type_subexpr::INT && - expr_s[i].sub_expr_s[j].subexpr_t != subexpressions::type_subexpr::ID) - throw semantic_excp( - build_pos_subexpr_str(expr_s[i].sub_expr_s[j]) + " Expected: [NUMBER] OR [VAR ID]\n", "001"); - - if (j == expr_s[i].sub_expr_s.size() - 1 && - current_expected_param < expr_s[i].expr_func.func_n.expected_params.size() - 1 && - expr_s[i].expr_func.func_n.expected_params[current_expected_param + 1].param_t != - param_type::NEXT_TOO && - !expr_s[i].expr_func.func_n.expected_params[current_expected_param + 1].decl_default_val()) - throw semantic_excp(build_pos_subexpr_str(expr_s[i].sub_expr_s[j]) + - " Expected: next parameter with the type is - [" + - parser::utility::type_sybexpr_str(aef_expr::conv_param_type_to_subexpr_type( - expr_s[i].expr_func.func_n.expected_params[j + 1].param_t)) + - "]\n", - "001"); + st_s[i].expr_s[j].type != expression::expression_t::STRING && + st_s[i].expr_s[j].type != expression::expression_t::NUMBER && + st_s[i].expr_s[j].type != expression::expression_t::ID) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS + << " Expected: [STRING], [NUMBER] OR [VAR ID] - " << st_s[i].expr_s[j].value); + else if (st_s[i].expr_func->expected_params[current_expected_param].type == param_type::LIT_STR && + st_s[i].expr_s[j].type != expression::expression_t::STRING) + _log << bwtools::fatal + << (log_message(log_type::fatal) << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS + << " Expected: [STRING] - " << st_s[i].expr_s[j].value); + else if (st_s[i].expr_func->expected_params[current_expected_param].type == param_type::LIT_NUM && + st_s[i].expr_s[j].type != expression::expression_t::NUMBER) + _log << bwtools::fatal + << (log_message(log_type::fatal) << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS + << " Expected: [NUMBER] - " << st_s[i].expr_s[j].value); + else if (st_s[i].expr_func->expected_params[current_expected_param].type == param_type::LSTR_OR_ID_VAR && + st_s[i].expr_s[j].type != expression::expression_t::STRING && + st_s[i].expr_s[j].type != expression::expression_t::ID) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS + << " Expected: [STRING] or [VAR ID->[STRING]] - " << st_s[i].expr_s[j].value); + else if (st_s[i].expr_func->expected_params[current_expected_param].type == param_type::LNUM_OR_ID_VAR && + st_s[i].expr_s[j].type != expression::expression_t::NUMBER && + st_s[i].expr_s[j].type != expression::expression_t::ID) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS + << " Expected: [NUMBER] or [VAR ID->[NUMBER]] - " << st_s[i].expr_s[j].value); + + if (j == st_s[i].expr_s.size() - 1 && + current_expected_param < st_s[i].expr_func->expected_params.size() - 1 && + st_s[i].expr_func->expected_params[current_expected_param + 1].type != param_type::NEXT_TOO && + !st_s[i].expr_func->expected_params[current_expected_param + 1].decl_default_val()) + _log << bwtools::fatal + << (log_message(log_type::fatal) << st_s[i].get_location() << ": " << NOT_MATCHING_W_PARAMETERS + << " Expected: next parameter with the type is - [" + << get_string_expr_type(conv_param_type_to_expr_type( + st_s[i].expr_func->expected_params[j + 1].type)) + << "] - " << st_s[i].expr_s[j].value); } } } -void semantic_analyzer::smt_second_pass(abstract_expr_func &expr_s, var::scope &curr_scope) { - +void semantic_analyzer::smt_second_pass(statements &st_s, var::scope ¤t_scope) { // <0 - if_skip, 1 - else_skip; 0 - current if, 1- current else> std::vector> branch_s; @@ -253,571 +195,291 @@ void semantic_analyzer::smt_second_pass(abstract_expr_func &expr_s, var::scope & bool skip = 0; - for (u32t i = 0; i < expr_s.size(); ++i) { + for (u32t i = 0; i < st_s.size(); ++i) { param_type before_nextt_param = param_type::SIZE_ENUM_PARAMS; u32t index_before_nextt_param = 0; - for (u32t j = 0; j < expr_s[i].sub_expr_s.size(); ++j) { - if (expr_s[i].sub_expr_s.size() == 0 || expr_s[i].sub_expr_s[0].token_of_subexpr.size() == 0) + for (u32t j = 0; j < st_s[i].expr_s.size(); ++j) { + if (st_s[i].expr_s.size() == 0 || st_s[i].expr_s[0].value.size() == 0) continue; else if (before_nextt_param == param_type::SIZE_ENUM_PARAMS && - expr_s[i].expr_func.func_n.expected_params[j].param_t == param_type::NEXT_TOO) { - before_nextt_param = expr_s[i].expr_func.func_n.expected_params[j - 1].param_t; + st_s[i].expr_func->expected_params[j].type == param_type::NEXT_TOO) { + before_nextt_param = st_s[i].expr_func->expected_params[j - 1].type; if (before_nextt_param == param_type::ANY_VALUE_WITHOUT_FUTUREID_NEXT) index_before_nextt_param = j - 1; } - for (u32t b = 0; b < expr_s[i].sub_expr_s[j].token_of_subexpr.size(); ++b) { - if (before_nextt_param != param_type::SIZE_ENUM_PARAMS) { - if (before_nextt_param == param_type::FUTURE_VAR_ID) { - u32t index_type = curr_scope.what_type(expr_s[i].sub_expr_s[j].token_of_subexpr[b].token_val); - if (index_type != 0) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: NEW [VAR ID]\n", - "010"); + if (before_nextt_param != param_type::SIZE_ENUM_PARAMS) { + if (before_nextt_param == param_type::FUTURE_VAR_ID) { + u32t index_type = current_scope.what_type(st_s[i].expr_s[j].value); + if (index_type != 0) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << EXPECTED_NEW_SYMBOL + << " Expected: NEW [VAR ID] - " << st_s[i].expr_s[j].value); + } + else if (before_nextt_param == param_type::NCHECK_VAR_ID) + continue; + else if (before_nextt_param == param_type::VAR_STRUCT_ID) { + u32t index_type = current_scope.what_type(st_s[i].expr_s[j].value); + if (index_type != 5 && index_type != 6) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << EXPECTED_EXIST_SYMBOL + << " Expected: [VAR STRUCT ID] - " << st_s[i].expr_s[j].value); + } + else if (before_nextt_param == param_type::ANY_VALUE_WITHOUT_FUTUREID_NEXT) { + if (st_s[i].expr_s[index_before_nextt_param].type == expression::expression_t::NUMBER && + st_s[i].expr_s[j].type != expression::expression_t::NUMBER) { + if (st_s[i].expr_s[j].type == expression::expression_t::ID) { + u32t index_type = current_scope.what_type(st_s[i].expr_s[j].value); + if (index_type == 1 || index_type == 3) + continue; + } + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << EXPECTED_ANOTHER_EXPR_TYPE + << " Expected: [NUMBER] - " << st_s[i].expr_s[j].value); } - else if (before_nextt_param == param_type::NCHECK_VAR_ID) - continue; - else if (before_nextt_param == param_type::VAR_STRUCT_ID) { - u32t index_type = curr_scope.what_type(expr_s[i].sub_expr_s[j].token_of_subexpr[b].token_val); - if (index_type != 5 && index_type != 6) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: [VAR STRUCT ID]\n", - "011"); + else if (st_s[i].expr_s[index_before_nextt_param].type == expression::expression_t::STRING && + st_s[i].expr_s[j].type != expression::expression_t::STRING) { + if (st_s[i].expr_s[j].type == expression::expression_t::ID) { + u32t index_type = current_scope.what_type(st_s[i].expr_s[j].value); + if (index_type == 2 || index_type == 4) + continue; + } + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << EXPECTED_ANOTHER_EXPR_TYPE + << " Expected: [STRING] - " << st_s[i].expr_s[j].value); } - else if (before_nextt_param == param_type::ANY_VALUE_WITHOUT_FUTUREID_NEXT) { - if (expr_s[i].sub_expr_s[index_before_nextt_param].returned_type_subexpr() == - subexpressions::ret_type_subexpr::INT && - expr_s[i].sub_expr_s[j].returned_type_subexpr() != subexpressions::ret_type_subexpr::INT) { - if (expr_s[i].sub_expr_s[j].returned_type_subexpr() == - subexpressions::ret_type_subexpr::ID) { - u32t index_type = - curr_scope.what_type(expr_s[i].sub_expr_s[j].token_of_subexpr[b].token_val); + else if (st_s[i].expr_s[index_before_nextt_param].type == expression::expression_t::ID) { + u32t index_type = current_scope.what_type(st_s[i].expr_s[index_before_nextt_param].value); + if ((index_type == 1 || index_type == 3) && + st_s[i].expr_s[j].type != expression::expression_t::NUMBER) { + if (st_s[i].expr_s[j].type == expression::expression_t::ID) { + u32t index_type = current_scope.what_type(st_s[i].expr_s[j].value); if (index_type == 1 || index_type == 3) continue; } - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: Expression with return type of INT\n", - "012"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << EXPECTED_ANOTHER_EXPR_TYPE + << " Expected: [NUMBER] - " << st_s[i].expr_s[j].value); } - else if (expr_s[i].sub_expr_s[index_before_nextt_param].returned_type_subexpr() == - subexpressions::ret_type_subexpr::STRING && - expr_s[i].sub_expr_s[j].returned_type_subexpr() != - subexpressions::ret_type_subexpr::STRING) { - if (expr_s[i].sub_expr_s[j].returned_type_subexpr() == - subexpressions::ret_type_subexpr::ID) { - u32t index_type = - curr_scope.what_type(expr_s[i].sub_expr_s[j].token_of_subexpr[b].token_val); + else if ((index_type == 2 || index_type == 4) && + st_s[i].expr_s[j].type != expression::expression_t::STRING) { + if (st_s[i].expr_s[j].type == expression::expression_t::ID) { + u32t index_type = current_scope.what_type(st_s[i].expr_s[j].value); if (index_type == 2 || index_type == 4) continue; } - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: Expression with return type of STRING\n", - "012"); - } - else if (expr_s[i].sub_expr_s[index_before_nextt_param].returned_type_subexpr() == - subexpressions::ret_type_subexpr::ID) { - u32t index_type = curr_scope.what_type( - expr_s[i].sub_expr_s[index_before_nextt_param].token_of_subexpr[0].token_val); - if ((index_type == 1 || index_type == 3) && - expr_s[i].sub_expr_s[j].returned_type_subexpr() != - subexpressions::ret_type_subexpr::INT) { - if (expr_s[i].sub_expr_s[j].returned_type_subexpr() == - subexpressions::ret_type_subexpr::ID) { - u32t index_type = - curr_scope.what_type(expr_s[i].sub_expr_s[j].token_of_subexpr[b].token_val); - if (index_type == 1 || index_type == 3) - continue; - } - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: Expression with return type of INT\n", - "012"); - } - else if ((index_type == 2 || index_type == 4) && - expr_s[i].sub_expr_s[j].returned_type_subexpr() != - subexpressions::ret_type_subexpr::STRING) { - if (expr_s[i].sub_expr_s[j].returned_type_subexpr() == - subexpressions::ret_type_subexpr::ID) { - u32t index_type = - curr_scope.what_type(expr_s[i].sub_expr_s[j].token_of_subexpr[b].token_val); - if (index_type == 2 || index_type == 4) - continue; - } - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: Expression with return type of STRING\n", - "012"); - } + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << EXPECTED_ANOTHER_EXPR_TYPE + << " Expected: [STRING] - " << st_s[i].expr_s[j].value); } } - else if (expr_s[i].sub_expr_s[j].token_of_subexpr[b].token_t == token_expr::token_type::ID) { - u32t index_type = curr_scope.what_type(expr_s[i].sub_expr_s[j].token_of_subexpr[b].token_val); - if (before_nextt_param == param_type::VAR_ID && index_type == 0) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: exist variable with any type\n", - "008"); - else if (index_type == 3 || index_type == 4) - continue; - else if (before_nextt_param == param_type::LNUM_OR_ID_VAR && index_type != 1 && - expr_s[i].sub_expr_s[j].returned_type_subexpr() != - subexpressions::ret_type_subexpr::INT) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: [VAR ID->[NUMBER]]\n", - "004"); - else if (before_nextt_param == param_type::LSTR_OR_ID_VAR && index_type != 2 && - expr_s[i].sub_expr_s[j].returned_type_subexpr() != - subexpressions::ret_type_subexpr::STRING) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: [VAR ID->[STRING]]\n", - "004"); - } - } - else if (expr_s[i].expr_func.func_n.expected_params[j].param_t == param_type::FUTURE_VAR_ID) { - u32t index_type = curr_scope.what_type(expr_s[i].sub_expr_s[j].token_of_subexpr[b].token_val); - if (index_type != 0) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: NEW [VAR ID]\n", - "010"); } - else if (expr_s[i].expr_func.func_n.expected_params[j].param_t == param_type::NCHECK_VAR_ID) { - continue; - } - else if (expr_s[i].expr_func.func_n.expected_params[j].param_t == param_type::VAR_STRUCT_ID) { - u32t index_type = curr_scope.what_type(expr_s[i].sub_expr_s[j].token_of_subexpr[b].token_val); - if (index_type != 5 && index_type != 6) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: [VAR STRUCT ID]\n", - "011"); + else if (st_s[i].expr_s[j].type == expression::expression_t::ID) { + u32t index_type = current_scope.what_type(st_s[i].expr_s[j].value); + if (before_nextt_param == param_type::VAR_ID && index_type == 0) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << IMPOSSIBLE_DETERMINE_TYPE_VAR + << " Expected: exist variable with any type - " << st_s[i].expr_s[j].value); + else if (index_type == 3 || index_type == 4) + continue; + else if (before_nextt_param == param_type::LNUM_OR_ID_VAR && index_type != 1 && + st_s[i].expr_s[j].type != expression::expression_t::NUMBER) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_EXIST_VAR_W_EXPECTED_TYPE + << " Expected: [VAR ID->[NUMBER]] - " << st_s[i].expr_s[j].value); + else if (before_nextt_param == param_type::LSTR_OR_ID_VAR && index_type != 2 && + st_s[i].expr_s[j].type != expression::expression_t::STRING) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_EXIST_VAR_W_EXPECTED_TYPE + << " Expected: [VAR ID->[STRING]] - " << st_s[i].expr_s[j].value); } - else if (expr_s[i].sub_expr_s[j].token_of_subexpr[b].token_t == token_expr::token_type::ID) { - u32t index_type = curr_scope.what_type(expr_s[i].sub_expr_s[j].token_of_subexpr[b].token_val); - if (index_type == 0) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: exist variable with any type\n", - "008"); - else if ((index_type == 3 || index_type == 4) && - j < expr_s[i].expr_func.func_n.expected_params.size() - 1) { - if (expr_s[i].expr_func.func_n.expected_params[j + 1].param_t != param_type::NEXT_TOO) - if (expr_s[i].expr_func.func_n.expected_params[j].param_t == param_type::LNUM_OR_ID_VAR) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: [VAR ID->[NUMBER]]\n", - "004"); - else - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: [VAR ID->[STRING]]\n", - "004"); - } - else if (expr_s[i].expr_func.func_n.expected_params[j].param_t == param_type::LNUM_OR_ID_VAR && - index_type != 1 && - expr_s[i].sub_expr_s[j].returned_type_subexpr() != subexpressions::ret_type_subexpr::INT) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: [VAR ID->[NUMBER]]\n", - "004"); - else if (expr_s[i].expr_func.func_n.expected_params[j].param_t == param_type::LSTR_OR_ID_VAR && - index_type != 2 && - expr_s[i].sub_expr_s[j].returned_type_subexpr() != - subexpressions::ret_type_subexpr::STRING) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: [VAR ID->[STRING]]\n", - "004"); - else if (index_type == 5 || index_type == 6) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].sub_expr_s[j].token_of_subexpr[b]) + - " Expected: [VAR ID->([NUMBER] or [STRING])]\n", - "004"); + } + else if (st_s[i].expr_func->expected_params[j].type == param_type::FUTURE_VAR_ID) { + u32t index_type = current_scope.what_type(st_s[i].expr_s[j].value); + if (index_type != 0) + _log << bwtools::fatal + << (log_message(log_type::fatal) << st_s[i].get_location() << ": " << EXPECTED_NEW_SYMBOL + << " Expected: NEW [VAR ID] - " << st_s[i].expr_s[j].value); + } + else if (st_s[i].expr_func->expected_params[j].type == param_type::NCHECK_VAR_ID) + continue; + else if (st_s[i].expr_func->expected_params[j].type == param_type::VAR_STRUCT_ID) { + u32t index_type = current_scope.what_type(st_s[i].expr_s[j].value); + if (index_type != 5 && index_type != 6) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << EXPECTED_EXIST_SYMBOL + << " Expected: [VAR STRUCT ID] - " << st_s[i].expr_s[j].value); + } + else if (st_s[i].expr_s[j].type == expression::expression_t::ID) { + u32t index_type = current_scope.what_type(st_s[i].expr_s[j].value); + if (index_type == 0) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << IMPOSSIBLE_DETERMINE_TYPE_VAR + << " Expected: exist variable with any type - " << st_s[i].expr_s[j].value); + else if ((index_type == 3 || index_type == 4) && j < st_s[i].expr_func->expected_params.size() - 1) { + if (st_s[i].expr_func->expected_params[j + 1].type != param_type::NEXT_TOO) + if (st_s[i].expr_func->expected_params[j].type == param_type::LNUM_OR_ID_VAR) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_EXIST_VAR_W_EXPECTED_TYPE + << " Expected: [VAR ID->[NUMBER]] - " << st_s[i].expr_s[j].value); + else + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_EXIST_VAR_W_EXPECTED_TYPE + << " Expected: [VAR ID->[STRING]] - " << st_s[i].expr_s[j].value); } + else if (st_s[i].expr_func->expected_params[j].type == param_type::LNUM_OR_ID_VAR && index_type != 1 && + st_s[i].expr_s[j].type != expression::expression_t::NUMBER) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_EXIST_VAR_W_EXPECTED_TYPE + << " Expected: [VAR ID->[NUMBER]] - " << st_s[i].expr_s[j].value); + else if (st_s[i].expr_func->expected_params[j].type == param_type::LSTR_OR_ID_VAR && index_type != 2 && + st_s[i].expr_s[j].type != expression::expression_t::STRING) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_EXIST_VAR_W_EXPECTED_TYPE + << " Expected: [VAR ID->[STRING]] - " << st_s[i].expr_s[j].value); + else if (index_type == 5 || index_type == 6) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << st_s[i].get_location() << ": " << NOT_EXIST_VAR_W_EXPECTED_TYPE + << " Expected: [VAR ID->([NUMBER] or [STRING])] - " << st_s[i].expr_s[j].value); } } - for (u32t j = 0, b = 0; j < expr_s[i].sub_expr_s.size(); ++j, ++b) { - if (b >= expr_s[i].expr_func.func_n.expected_params.size() && - before_nextt_param != param_type::SIZE_ENUM_PARAMS) { - parse_subexpr_param( - expr_s[i].sub_expr_s[j], expr_s[i].sub_expr_s, j, curr_scope, - expr_s[i] - .expr_func.func_n.expected_params[expr_s[i].expr_func.func_n.expected_params.size() - 1] - .param_t); + for (u32t j = 0, b = 0; j < st_s[i].expr_s.size(); ++j, ++b) { + if (b >= st_s[i].expr_func->expected_params.size() && before_nextt_param != param_type::SIZE_ENUM_PARAMS) { + parse_expr_param( + st_s[i].expr_s[j], st_s[i].expr_s, j, current_scope, + st_s[i].expr_func->expected_params[st_s[i].expr_func->expected_params.size() - 1].type); continue; } - parse_subexpr_param(expr_s[i].sub_expr_s[j], expr_s[i].sub_expr_s, j, curr_scope, - expr_s[i].expr_func.func_n.expected_params[b].param_t); + parse_expr_param(st_s[i].expr_s[j], st_s[i].expr_s, j, current_scope, + st_s[i].expr_func->expected_params[b].type); } // skips branches if (skip) { - if (expr_s[i].expr_func.func_t.token_val == STR_KEYWORD_IF) + if (st_s[i].expr_func->name_func == STR_KEYWORD_IF) ++nested_if; - else if (expr_s[i].expr_func.func_t.token_val == STR_KEYWORD_ELSE) + else if (st_s[i].expr_func->name_func == STR_KEYWORD_ELSE) ++nested_if; - else if (expr_s[i].expr_func.func_t.token_val == STR_KEYWORD_ENDIF) { + else if (st_s[i].expr_func->name_func == STR_KEYWORD_ENDIF) { if (!nested_if) goto endif_end; --nested_if; } - expr_s.erase(expr_s.begin() + i); + st_s.erase(st_s.begin() + i); --i; } // keyword handler(if, else, endif) - else if (expr_s[i].expr_func.func_t.token_t == token_expr::token_type::KEYWORD) { - if (expr_s[i].expr_func.func_t.token_val == STR_KEYWORD_IF) { - u32t val = std::stoi(expr_s[i].sub_expr_s[0].token_of_subexpr[0].token_val); - if (!val) { - skip = 1; - branch_s.push_back(std::pair(0, 0)); - } - else - branch_s.push_back(std::pair(1, 0)); - } - else if (expr_s[i].expr_func.func_t.token_val == STR_KEYWORD_ELSE) { - if (!branch_s.size() || branch_s[branch_s.size() - 1].second) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].expr_func.func_t), "015"); - - if (branch_s[branch_s.size() - 1].first) - skip = 1; - } - else if (expr_s[i].expr_func.func_t.token_val == STR_KEYWORD_ENDIF) { - endif_end: - if (!branch_s.size()) - throw semantic_excp(build_pos_tokenb_str(expr_s[i].expr_func.func_t), "014"); - - skip = 0; - if (branch_s[branch_s.size() - 1].second || - (i < expr_s.size() - 1 && expr_s[i + 1].expr_func.func_t.token_val != STR_KEYWORD_ELSE)) - branch_s.pop_back(); + if (st_s[i].expr_func->name_func == STR_KEYWORD_IF) { + u32t val = std::stoi(st_s[i].expr_s[0].value); + if (!val) { + skip = 1; + branch_s.push_back(std::pair(0, 0)); } else - throw semantic_excp(build_pos_tokenb_str(expr_s[i].expr_func.func_t), "016"); - expr_s.erase(expr_s.begin() + i); - --i; + branch_s.push_back(std::pair(1, 0)); + goto delete_entry; } - else if (expr_s[i].execute_with_semantic_an()) { - expr_s[i].expr_func.func_n.func_ref(expr_s[i].sub_expr_s, curr_scope); -#if defined(WIN) - assist.check_safe_call_dll_func(); -#elif defined(UNIX) - assist.check_safe_call_dl_func(); -#endif + else if (st_s[i].expr_func->name_func == STR_KEYWORD_ELSE) { + if (!branch_s.size() || branch_s[branch_s.size() - 1].second) + _log << bwtools::fatal + << (log_message(log_type::fatal) << st_s[i].get_location() << ": " << EXPECTED_IF); + + if (branch_s[branch_s.size() - 1].first) + skip = 1; + goto delete_entry; } - } - - if (branch_s.size()) - throw semantic_excp("End Of AEF", "013"); -} - -void semantic_analyzer::convert_id_to_literal(aef_expr::subexpressions &sub_expr, var::scope &curr_scope, - aef_expr::param_type expected_param) { - for (u32t i = 0; i < sub_expr.token_of_subexpr.size(); ++i) { - if (sub_expr.token_of_subexpr[i].token_t == token_expr::token_type::ID && - (expected_param != param_type::VAR_ID && expected_param != param_type::FUTURE_VAR_ID && - expected_param != param_type::NCHECK_VAR_ID)) { - u32t index_var = curr_scope.what_type(sub_expr.token_of_subexpr[i].token_val); - if (index_var == 1) { - sub_expr.token_of_subexpr[i] = token_expr::token( - token_expr::token_type::LITERAL, - std::to_string(curr_scope.get_var_value(sub_expr.token_of_subexpr[i].token_val.c_str())), - sub_expr.token_of_subexpr[i].pos_defined_line, sub_expr.token_of_subexpr[i].pos_beg_defined_sym); - } - else if (index_var == 2) { - sub_expr.token_of_subexpr[i] = token_expr::token( - token_expr::token_type::LITERALS, - curr_scope.get_var_value(sub_expr.token_of_subexpr[i].token_val), - sub_expr.token_of_subexpr[i].pos_defined_line, sub_expr.token_of_subexpr[i].pos_beg_defined_sym); - } + else if (st_s[i].expr_func->name_func == STR_KEYWORD_ENDIF) { + endif_end: + if (!branch_s.size()) + _log << bwtools::fatal + << (log_message(log_type::fatal) << st_s[i].get_location() << ": " << INVALID_USAGE_ENDIF); + + skip = 0; + if (branch_s[branch_s.size() - 1].second || + (i < st_s.size() - 1 && st_s[i + 1].expr_func->name_func != STR_KEYWORD_ELSE)) + branch_s.pop_back(); + goto delete_entry; } + st_s[i].expr_func->func(st_s[i].expr_s, current_scope); + continue; + delete_entry: + st_s.erase(st_s.begin() + i); + --i; } -} -void semantic_analyzer::convert_kwop_u_to_literal(aef_expr::subexpressions &sub_expr, var::scope &curr_scope, - aef_expr::param_type expected_param) { - for (u32t i = 0; i < sub_expr.token_of_subexpr.size(); ++i) { - if (sub_expr.token_of_subexpr[i].token_t == token_expr::token_type::KW_OPERATOR && - IS_UNARY_KW_OP(sub_expr.token_of_subexpr[i].token_val)) - parse_keywords_op_param(sub_expr, i, curr_scope, expected_param, 1); - } + if (branch_s.size()) + _log << bwtools::fatal << (log_message(log_type::fatal) << "End of statements: " << EXPECTED_ENDIF); } - -void semantic_analyzer::parse_subexpr_param(subexpressions &sub_expr, std::vector &sub_exprs, - u32t &pos_sub_expr_in_vec, var::scope &curr_scope, - param_type expected_param) { - subexpressions parse_subexpr, tmp_parse_subexpr; - if (sub_expr.subexpr_t == subexpressions::type_subexpr::INT_COMPARE) { - for (u32t i = 0; i < sub_expr.token_of_subexpr.size(); ++i) { - if (sub_expr.token_of_subexpr[i].token_t == token_expr::token_type::ID) { - parse_subexpr.token_of_subexpr.push_back(token_expr::token( - token_expr::token_type::LITERAL, - std::to_string(curr_scope.get_var_value(sub_expr.token_of_subexpr[i].token_val.c_str())), - sub_expr.token_of_subexpr[i].pos_defined_line, sub_expr.token_of_subexpr[i].pos_beg_defined_sym)); - if (parse_subexpr.token_of_subexpr.size() == 3) - goto parse_integer; - continue; - } - parse_subexpr.token_of_subexpr.push_back(sub_expr.token_of_subexpr[i]); - if (parse_subexpr.token_of_subexpr.size() == 3) { - parse_integer: - bool condition = 0; - switch (parse_subexpr.token_of_subexpr[1].token_val[0]) { - case '>': - if (std::stoi(parse_subexpr.token_of_subexpr[0].token_val.c_str()) > - std::stoi(parse_subexpr.token_of_subexpr[2].token_val.c_str())) - condition = 1; - break; - case '<': - if (std::stoi(parse_subexpr.token_of_subexpr[0].token_val.c_str()) < - std::stoi(parse_subexpr.token_of_subexpr[2].token_val.c_str())) - condition = 1; - break; - case '=': - if (std::stoi(parse_subexpr.token_of_subexpr[0].token_val.c_str()) == - std::stoi(parse_subexpr.token_of_subexpr[2].token_val.c_str())) - condition = 1; - break; - } - tmp_parse_subexpr = parse_subexpr; - parse_subexpr.token_of_subexpr.clear(); - if (condition) - parse_subexpr.token_of_subexpr.push_back(token_expr::token( - token_expr::token_type::LITERAL, "1", tmp_parse_subexpr.token_of_subexpr[0].pos_defined_line, - tmp_parse_subexpr.token_of_subexpr[0].pos_beg_defined_sym)); - else - parse_subexpr.token_of_subexpr.push_back(token_expr::token( - token_expr::token_type::LITERAL, "0", tmp_parse_subexpr.token_of_subexpr[0].pos_defined_line, - tmp_parse_subexpr.token_of_subexpr[0].pos_beg_defined_sym)); - } - } - } - else if (sub_expr.subexpr_t == subexpressions::type_subexpr::STRING_ADD) { - for (u32t i = 0; i < sub_expr.token_of_subexpr.size(); ++i) { - if (sub_expr.token_of_subexpr[i].token_t == token_expr::token_type::ID) { - parse_subexpr.token_of_subexpr.push_back(token_expr::token( - token_expr::token_type::LITERALS, - curr_scope.get_var_value(sub_expr.token_of_subexpr[i].token_val), - sub_expr.token_of_subexpr[i].pos_defined_line, sub_expr.token_of_subexpr[i].pos_beg_defined_sym)); - if (parse_subexpr.token_of_subexpr.size() == 3) - goto parse_string; - continue; - } - parse_subexpr.token_of_subexpr.push_back(sub_expr.token_of_subexpr[i]); - if (parse_subexpr.token_of_subexpr.size() == 3) { - parse_string: - tmp_parse_subexpr = parse_subexpr; - parse_subexpr.token_of_subexpr.clear(); - parse_subexpr.token_of_subexpr.push_back(token_expr::token( - token_expr::token_type::LITERALS, - tmp_parse_subexpr.token_of_subexpr[0].token_val + tmp_parse_subexpr.token_of_subexpr[2].token_val, - tmp_parse_subexpr.token_of_subexpr[0].pos_defined_line, - tmp_parse_subexpr.token_of_subexpr[0].pos_beg_defined_sym)); - } - } - } - else if (sub_expr.subexpr_t == subexpressions::type_subexpr::ID && - (expected_param != param_type::VAR_ID && expected_param != param_type::FUTURE_VAR_ID && - expected_param != param_type::NCHECK_VAR_ID)) { - u32t index_var = curr_scope.what_type(sub_expr.token_of_subexpr[0].token_val); +void semantic_analyzer::parse_expr_param(expression &expr, expressions &expr_s, u32t &pos_expr_in_vec, + var::scope ¤t_scope, param_type expected_param) { + expression parse_expr, tmp_parse_expr; + if (expr.type == expression::expression_t::ID && + (expected_param != param_type::VAR_ID && expected_param != param_type::FUTURE_VAR_ID && + expected_param != param_type::NCHECK_VAR_ID)) { + u32t index_var = current_scope.what_type(expr.value); if (index_var == 1) { - parse_subexpr.subexpr_t = subexpressions::type_subexpr::INT; - parse_subexpr.token_of_subexpr.push_back(token_expr::token( - token_expr::token_type::LITERAL, - std::to_string(curr_scope.get_var_value(sub_expr.token_of_subexpr[0].token_val.c_str())), - sub_expr.token_of_subexpr[0].pos_defined_line, sub_expr.token_of_subexpr[0].pos_beg_defined_sym)); + parse_expr.type = expression::expression_t::NUMBER; + parse_expr.value = std::to_string(current_scope.get_var_value(expr.value)); } else if (index_var == 2) { - parse_subexpr.subexpr_t = subexpressions::type_subexpr::STRING; - parse_subexpr.token_of_subexpr.push_back(token_expr::token( - token_expr::token_type::LITERALS, - curr_scope.get_var_value(sub_expr.token_of_subexpr[0].token_val), - sub_expr.token_of_subexpr[0].pos_defined_line, sub_expr.token_of_subexpr[0].pos_beg_defined_sym)); + parse_expr.type = expression::expression_t::STRING; + parse_expr.value = current_scope.get_var_value(expr.value); } else if (index_var == 3) { - std::vector new_sub_exprs; - subexpressions tmp_sub_expr; - tmp_sub_expr.subexpr_t = subexpressions::type_subexpr::INT; - const std::vector vec_int_id = - curr_scope.get_var_value>(sub_expr.token_of_subexpr[0].token_val); - for (u32t i = 0; i < pos_sub_expr_in_vec; ++i) - new_sub_exprs.push_back(sub_exprs[i]); + expressions new_expr_s; + expression tmp_expr; + tmp_expr.type = expression::expression_t::NUMBER; + const std::vector vec_int_id = current_scope.get_var_value>(expr.value); + for (u32t i = 0; i < pos_expr_in_vec; ++i) + new_expr_s.push_back(expr_s[i]); for (u32t i = 0; i < vec_int_id.size(); ++i) { - tmp_sub_expr.token_of_subexpr.push_back(token_expr::token( - token_expr::token_type::LITERAL, std::to_string(vec_int_id[i]), - sub_expr.token_of_subexpr[0].pos_defined_line, sub_expr.token_of_subexpr[0].pos_beg_defined_sym)); - new_sub_exprs.push_back(tmp_sub_expr); - tmp_sub_expr.token_of_subexpr.clear(); + tmp_expr.value = std::to_string(vec_int_id[i]); + new_expr_s.push_back(tmp_expr); + tmp_expr.value = ""; } - for (u32t i = pos_sub_expr_in_vec + 1; i < sub_exprs.size(); ++i) - new_sub_exprs.push_back(sub_exprs[i]); - pos_sub_expr_in_vec += vec_int_id.size() - 1; - sub_exprs = new_sub_exprs; + for (u32t i = pos_expr_in_vec + 1; i < expr_s.size(); ++i) + new_expr_s.push_back(expr_s[i]); + pos_expr_in_vec += vec_int_id.size() - 1; + expr_s = new_expr_s; } else if (index_var == 4) { - std::vector new_sub_exprs; - subexpressions tmp_sub_expr; - tmp_sub_expr.subexpr_t = subexpressions::type_subexpr::STRING; + expressions new_expr_s; + expression tmp_expr; + tmp_expr.type = expression::expression_t::STRING; const std::vector vec_str_id = - curr_scope.get_var_value>(sub_expr.token_of_subexpr[0].token_val); - for (u32t i = 0; i < pos_sub_expr_in_vec; ++i) - new_sub_exprs.push_back(sub_exprs[i]); + current_scope.get_var_value>(expr.value); + for (u32t i = 0; i < pos_expr_in_vec; ++i) + new_expr_s.push_back(expr_s[i]); for (u32t i = 0; i < vec_str_id.size(); ++i) { - tmp_sub_expr.token_of_subexpr.push_back(token_expr::token( - token_expr::token_type::LITERALS, vec_str_id[i], sub_expr.token_of_subexpr[0].pos_defined_line, - sub_expr.token_of_subexpr[0].pos_beg_defined_sym)); - new_sub_exprs.push_back(tmp_sub_expr); - tmp_sub_expr.token_of_subexpr.clear(); + tmp_expr.value = vec_str_id[i]; + new_expr_s.push_back(tmp_expr); + tmp_expr.value = ""; } - for (u32t i = pos_sub_expr_in_vec + 1; i < sub_exprs.size(); ++i) - new_sub_exprs.push_back(sub_exprs[i]); - pos_sub_expr_in_vec += vec_str_id.size() - 1; - sub_exprs = new_sub_exprs; + for (u32t i = pos_expr_in_vec + 1; i < expr_s.size(); ++i) + new_expr_s.push_back(expr_s[i]); + pos_expr_in_vec += vec_str_id.size() - 1; + expr_s = new_expr_s; } - if (parse_subexpr.token_of_subexpr.size() > 0) - sub_expr = parse_subexpr; + if (!parse_expr.value.empty()) + expr = parse_expr; return; } - else if (sub_expr.subexpr_t == subexpressions::type_subexpr::KEYWORD_OP) { - convert_id_to_literal(sub_expr, curr_scope, expected_param); - convert_kwop_u_to_literal(sub_expr, curr_scope, expected_param); - parse_keywords_op_param(sub_expr, UINT32_MAX, curr_scope, expected_param); - if (sub_expr.token_of_subexpr[0].token_t == token_expr::token_type::LITERAL) - sub_expr.subexpr_t = subexpressions::type_subexpr::INT; - else if (sub_expr.token_of_subexpr[0].token_t == token_expr::token_type::LITERALS) - sub_expr.subexpr_t = subexpressions::type_subexpr::STRING; - return; - } - else - return; - - if (parse_subexpr.token_of_subexpr[0].token_t == token_expr::token_type::LITERAL) - parse_subexpr.subexpr_t = subexpressions::type_subexpr::INT; - else - parse_subexpr.subexpr_t = subexpressions::type_subexpr::STRING; - sub_expr = parse_subexpr; -} -void semantic_analyzer::parse_keywords_op_param(aef_expr::subexpressions &sub_expr, u32t pos_token_kw_in_subexpr, - var::scope &curr_scope, aef_expr::param_type expected_param, - u32t parse_okeyword) { - if (pos_token_kw_in_subexpr == UINT32_MAX) { - for (u32t i = 0; i < sub_expr.token_of_subexpr.size(); ++i) - if (sub_expr.token_of_subexpr[i].token_t == token_expr::token_type::KW_OPERATOR) { - pos_token_kw_in_subexpr = i; - break; - } - if (pos_token_kw_in_subexpr == UINT32_MAX) - return; - } - - if (IS_BIBARY_KW_OP(sub_expr.token_of_subexpr[pos_token_kw_in_subexpr].token_val)) { - if (RET_INT_KW_OP(sub_expr.token_of_subexpr[pos_token_kw_in_subexpr].token_val)) { - if (expected_param != param_type::LNUM_OR_ID_VAR && - expected_param != param_type::ANY_VALUE_WITHOUT_FUTUREID_NEXT || - pos_token_kw_in_subexpr == 0 || pos_token_kw_in_subexpr == sub_expr.token_of_subexpr.size() - 1) - throw semantic_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[pos_token_kw_in_subexpr]) + - " Two operands are expected", - "017"); - if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr].token_val == STR_KEYWORD_OP_EQUAL) { - if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_t == token_expr::token_type::LITERAL) { - if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_t != - token_expr::token_type::LITERAL) - throw semantic_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[pos_token_kw_in_subexpr]) + - " Expected literal(int): " + - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_val, - "018"); - } - else if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_t == - token_expr::token_type::LITERALS) { - if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_t != - token_expr::token_type::LITERALS) - throw semantic_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[pos_token_kw_in_subexpr]) + - " Expected literal(string): " + - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_val, - "018"); - } - else - throw semantic_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[pos_token_kw_in_subexpr]) + - " Inappropriate parameter for keyword operator: " + - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_val, - "018"); - - if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_val == - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_val) { - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_t = token_expr::token_type::LITERAL; - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_val = "1"; - } - else { - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_t = token_expr::token_type::LITERAL; - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_val = "0"; - } - } - else if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr].token_val == STR_KEYWORD_OP_AND) { - if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_t != token_expr::token_type::LITERAL || - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_t != token_expr::token_type::LITERAL) - throw semantic_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[pos_token_kw_in_subexpr]) + - " Expected literal(int): " + - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_val, - "018"); - if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_val == "1" && - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_val == "1") - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_val = "1"; - else - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_val = "0"; - } - else if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr].token_val == STR_KEYWORD_OP_OR) { - if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_t != token_expr::token_type::LITERAL || - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_t != token_expr::token_type::LITERAL) - throw semantic_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[pos_token_kw_in_subexpr]) + - " Expected literal(int): " + - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_val, - "018"); - if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_val == "1" || - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_val == "1") - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_val = "1"; - else - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr - 1].token_val = "0"; - } - } - sub_expr.token_of_subexpr.erase(sub_expr.token_of_subexpr.begin() + pos_token_kw_in_subexpr + 1); - sub_expr.token_of_subexpr.erase(sub_expr.token_of_subexpr.begin() + pos_token_kw_in_subexpr); - } - else if (IS_UNARY_KW_OP(sub_expr.token_of_subexpr[pos_token_kw_in_subexpr].token_val)) { - if (pos_token_kw_in_subexpr == sub_expr.token_of_subexpr.size() - 1) - throw semantic_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[pos_token_kw_in_subexpr]) + - " One operands are expected", - "017"); - if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_t == token_expr::token_type::KW_OPERATOR) - parse_keywords_op_param(sub_expr, pos_token_kw_in_subexpr + 1, curr_scope, expected_param, 1); - if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr].token_val == STR_KEYWORD_OP_TSTR) { - if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_t == token_expr::token_type::LITERAL) { - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr].token_t = token_expr::token_type::LITERALS; - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr].token_val = - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_val; - } - else - throw semantic_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[pos_token_kw_in_subexpr]) + - " Inappropriate parameter for keyword operator: " + - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_val, - "018"); - } - else if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr].token_val == STR_KEYWORD_OP_NOT) { - if (sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_t != token_expr::token_type::LITERAL) - throw semantic_excp(build_pos_tokenb_str(sub_expr.token_of_subexpr[pos_token_kw_in_subexpr]) + - " Inappropriate parameter for keyword operator: " + - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_val, - "018"); - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr].token_t = token_expr::token_type::LITERAL; - sub_expr.token_of_subexpr[pos_token_kw_in_subexpr].token_val = - std::atoll(sub_expr.token_of_subexpr[pos_token_kw_in_subexpr + 1].token_val.c_str()) != 0 ? "0" : "1"; - } - sub_expr.token_of_subexpr.erase(sub_expr.token_of_subexpr.begin() + pos_token_kw_in_subexpr + 1); - } - - if (sub_expr.token_of_subexpr.size() != 1 && !parse_okeyword) - parse_keywords_op_param(sub_expr, UINT32_MAX, curr_scope, expected_param); -} - -void semantic_analyzer::defining_call_func(const std::string &name, notion_func &nfunc) { - if (std::find_if(nfunc.expected_params.begin(), nfunc.expected_params.end(), - [](const param &_param) { return _param.param_t == param_type::FUTURE_VAR_ID; }) != - nfunc.expected_params.end() || - std::find_if(nfunc.expected_params.begin(), nfunc.expected_params.end(), [](const param &_param) { - return _param.param_t == param_type::NCHECK_VAR_ID; - }) != nfunc.expected_params.end()) - nfunc.is_declaration_var = 1; - else if (std::find(name_func_with_semantic_an.begin(), name_func_with_semantic_an.end(), name) != - name_func_with_semantic_an.end()) - nfunc.only_with_semantic = 1; } diff --git a/src/bs/lang/semantic_an.hpp b/src/bs/lang/semantic_an.hpp index a0469ee..4e59b35 100644 --- a/src/bs/lang/semantic_an.hpp +++ b/src/bs/lang/semantic_an.hpp @@ -1,55 +1,14 @@ #ifndef _SEMANTIC_AN__H #define _SEMANTIC_AN__H -#include "parser.hpp" -#include "scope.hpp" -#include "static_linking_func.hpp" - -#include - -namespace semantic_an { - -using table_func = std::unordered_map; - -extern var::scope global_scope; - -class semantic_excp : public ::bwexception::bweas_exception { - public: - semantic_excp(std::string _what_hp, std::string number_err) - : what_hp(_what_hp), bweas_exception("SMT" + number_err) { - } - ~semantic_excp() noexcept override final = default; - - public: - const char *what() const noexcept override final { - return what_hp.c_str(); - } - - private: - std::string what_hp; -}; - -class rt_semantic_excp : public ::bwexception::bweas_exception { - public: - rt_semantic_excp(std::string _what_hp, std::string number_err) - : what_hp(_what_hp), bweas_exception("SMT-RT" + number_err) { - } - ~rt_semantic_excp() noexcept override final = default; - - public: - const char *what() const noexcept override final { - return what_hp.c_str(); - } - - private: - std::string what_hp; -}; +#include class semantic_analyzer { public: - semantic_analyzer(); - semantic_analyzer(semantic_analyzer &&) = delete; - semantic_analyzer(const semantic_analyzer &) = delete; + semantic_analyzer(logger &_log); + + semantic_analyzer(semantic_analyzer &&) = delete; + semantic_analyzer(const semantic_analyzer &) = delete; semantic_analyzer &operator=(semantic_analyzer &&) = delete; ~semantic_analyzer() = default; @@ -57,14 +16,6 @@ class semantic_analyzer { public: // Semantic analysis: // ------------------ - // - It goes through the vector of expressions - // and determines the use of external functions; - // if an external function was used, - // it will be added to the list of functions that can be called - // - // ^^^ - // zero pass - // // - linking all representations of functions // in expressions with functions that describe their behavior. // Checks the correspondence of the transmitted types of indicators @@ -81,51 +32,22 @@ class semantic_analyzer { // ^^^ // second pass // - void analysis(parser::abstract_expr_func &expr_s, var::scope &global_scope); - - void load_external_func_table(const table_func ¬ion_external_func); - void append_external_name_func_w_smt(const std::vector &list_name_func); - - // Adding a function definition to the functions table - void add_func_flink(std::string name_token_func, aef_expr::notion_func::func_t func_ref, - std::vector expected_param); + void analysis(statements &st_s, var::scope ¤t_scope); private: - void smt_zero_pass(const parser::abstract_expr_func &expr_s); - void smt_first_pass(parser::abstract_expr_func &expr_s); + void smt_first_pass(statements &st_s, var::scope ¤t_scope); // The set command (initialization or assignment) is called here - void smt_second_pass(parser::abstract_expr_func &expr_s, var::scope &curr_scope); + void smt_second_pass(statements &st_s, var::scope ¤t_scope); private: - // Converts all variable identifiers to their values and also keyword operators(constant) to literal ​​(for - // subsequent processing of keyword operators) - void convert_id_to_literal(aef_expr::subexpressions &sub_expr, var::scope &curr_scope, - aef_expr::param_type expected_param); - - // Converts all keyword operators that are unary - void convert_kwop_u_to_literal(aef_expr::subexpressions &sub_expr, var::scope &curr_scope, - aef_expr::param_type expected_param); // Parses a subexpression if it has not token the type // INT, STRING, or VAR_STRUCT_ID after parsing at the AEF construction - void parse_subexpr_param(aef_expr::subexpressions &sub_expr, std::vector &sub_exprs, - u32t &pos_sub_expr_in_vec, var::scope &curr_scope, aef_expr::param_type expected_param); - - // Auxiliary function for parse_subexpr_param. Processes all keyword operators - void parse_keywords_op_param(aef_expr::subexpressions &sub_expr, u32t pos_token_kw_in_subexpr, - var::scope &curr_scope, aef_expr::param_type expected_param, u32t parse_okeyword = 0); - void defining_call_func(const std::string &name, aef_expr::notion_func &nfunc); + void parse_expr_param(expression &expr, expressions &expr_s, u32t &pos_expr_in_vec, var::scope ¤t_scope, + param_type expected_param); private: - static inline bool init_glob{0}; - - std::vector name_func_with_semantic_an{sl_func::name_static_func_sm}; - - // functions tables - table_func notion_all_func; - table_func notion_external_func; + logger &_log; }; -} // namespace semantic_an - -#endif \ No newline at end of file +#endif diff --git a/src/bs/lang/static_linking_func.cpp b/src/bs/lang/static_linking_func.cpp index cded13d..0c5e329 100644 --- a/src/bs/lang/static_linking_func.cpp +++ b/src/bs/lang/static_linking_func.cpp @@ -1,17 +1,13 @@ #include "static_linking_func.hpp" + #include "../tools/bwfile.hpp" #include "interpreter.hpp" -#include "parser.hpp" -#include "semantic_an.hpp" #include #include -using namespace aef_expr; - std::map var::struct_sb::project::preset_ext_fields; -const std::vector sl_func::name_static_func_sm = {"exp_data"}; static const std::array vec_name_config_var = { PRJ_VAR_NAME_DFLAGS_C, PRJ_VAR_NAME_DFLAGS_L, PRJ_VAR_NAME_RFLAGS_C, PRJ_VAR_NAME_RFLAGS_L, PRJ_VAR_NAME_LANG, PRJ_VAR_NAME_PTH_C, PRJ_VAR_NAME_PTH_L, PRJ_VAR_NAME_VER, @@ -19,139 +15,141 @@ static const std::array vec_name_config_var = { PRJ_VAR_NAME_UITTEMPLATES, TRG_VAR_NAME_NPROJECT, TRG_VAR_NAME_VER, TRG_VAR_NAME_CFG, TRG_VAR_NAME_TYPE_T, TRG_VAR_NAME_LLIBS}; +static bweas::logger _log{"STATUS"}; + // ?????? -static void update_cfg_struct(const std::string &name_var, var::scope &curr_scope) { - if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT)) { +static void update_cfg_struct(const std::string &name_var, var::scope ¤t_scope) { + if (current_scope.what_type(DECL_VAR_STRUCT) == 1 && current_scope.get_var_value(DECL_VAR_STRUCT)) { u32t tmp_it = 0; for (const auto &it : vec_name_config_var) { if ((tmp_it = name_var.find(it)) != SIZE_MAX) { if (name_var.size() - it.size() != tmp_it) return; std::string tmp_str_postfix = name_var; - std::string tmp_str_prefix = name_var; + std::string tmp_str_prefix = name_var; tmp_str_postfix.erase(0, tmp_it); tmp_str_prefix.erase(tmp_it, tmp_str_prefix.size()); if (tmp_str_postfix == PRJ_VAR_NAME_DFLAGS_C) { - if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 2) + if (current_scope.what_type(tmp_str_prefix) != 5 || current_scope.what_type(name_var) != 2) return; - curr_scope.get_var_value(tmp_str_prefix).dflags_compiler = - curr_scope.get_var_value(name_var); + current_scope.get_var_value(tmp_str_prefix).dflags_compiler = + current_scope.get_var_value(name_var); } else if (tmp_str_postfix == PRJ_VAR_NAME_DFLAGS_L) { - if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 2) + if (current_scope.what_type(tmp_str_prefix) != 5 || current_scope.what_type(name_var) != 2) return; - curr_scope.get_var_value(tmp_str_prefix).dflags_linker = - curr_scope.get_var_value(name_var); + current_scope.get_var_value(tmp_str_prefix).dflags_linker = + current_scope.get_var_value(name_var); } else if (tmp_str_postfix == PRJ_VAR_NAME_RFLAGS_C) { - if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 2) + if (current_scope.what_type(tmp_str_prefix) != 5 || current_scope.what_type(name_var) != 2) return; - curr_scope.get_var_value(tmp_str_prefix).rflags_compiler = - curr_scope.get_var_value(name_var); + current_scope.get_var_value(tmp_str_prefix).rflags_compiler = + current_scope.get_var_value(name_var); } else if (tmp_str_postfix == PRJ_VAR_NAME_RFLAGS_L) { - if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 2) + if (current_scope.what_type(tmp_str_prefix) != 5 || current_scope.what_type(name_var) != 2) return; - curr_scope.get_var_value(tmp_str_prefix).rflags_linker = - curr_scope.get_var_value(name_var); + current_scope.get_var_value(tmp_str_prefix).rflags_linker = + current_scope.get_var_value(name_var); } else if (tmp_str_postfix == PRJ_VAR_NAME_PTH_C) { - if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 2) + if (current_scope.what_type(tmp_str_prefix) != 5 || current_scope.what_type(name_var) != 2) return; - curr_scope.get_var_value(tmp_str_prefix).path_compiler = - curr_scope.get_var_value(name_var); + current_scope.get_var_value(tmp_str_prefix).path_compiler = + current_scope.get_var_value(name_var); } else if (tmp_str_postfix == PRJ_VAR_NAME_PTH_L) { - if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 2) + if (current_scope.what_type(tmp_str_prefix) != 5 || current_scope.what_type(name_var) != 2) return; - curr_scope.get_var_value(tmp_str_prefix).path_linker = - curr_scope.get_var_value(name_var); + current_scope.get_var_value(tmp_str_prefix).path_linker = + current_scope.get_var_value(name_var); } else if (tmp_str_postfix == PRJ_VAR_NAME_STD_C) { - if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 1) + if (current_scope.what_type(tmp_str_prefix) != 5 || current_scope.what_type(name_var) != 1) return; - curr_scope.get_var_value(tmp_str_prefix).standart_c = - curr_scope.get_var_value(name_var); + current_scope.get_var_value(tmp_str_prefix).standart_c = + current_scope.get_var_value(name_var); } else if (tmp_str_postfix == PRJ_VAR_NAME_STD_CPP) { - if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 1) + if (current_scope.what_type(tmp_str_prefix) != 5 || current_scope.what_type(name_var) != 1) return; - curr_scope.get_var_value(tmp_str_prefix).standart_cpp = - curr_scope.get_var_value(name_var); + current_scope.get_var_value(tmp_str_prefix).standart_cpp = + current_scope.get_var_value(name_var); } else if (tmp_str_postfix == PRJ_VAR_NAME_LANG) { - if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 1) + if (current_scope.what_type(tmp_str_prefix) != 5 || current_scope.what_type(name_var) != 1) return; - curr_scope.get_var_value(tmp_str_prefix).language = - curr_scope.get_var_value(name_var); + current_scope.get_var_value(tmp_str_prefix).language = + current_scope.get_var_value(name_var); } else if (tmp_str_postfix == PRJ_VAR_NAME_VER) { - if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 2) + if (current_scope.what_type(tmp_str_prefix) != 5 || current_scope.what_type(name_var) != 2) return; - curr_scope.get_var_value(tmp_str_prefix).version_project = - var::struct_sb::version(curr_scope.get_var_value(name_var)); + current_scope.get_var_value(tmp_str_prefix).version_project = + var::struct_sb::version(current_scope.get_var_value(name_var)); } else if (tmp_str_postfix == PRJ_VAR_NAME_SRC_FILES) { - if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 4) + if (current_scope.what_type(tmp_str_prefix) != 5 || current_scope.what_type(name_var) != 4) return; - curr_scope.get_var_value(tmp_str_prefix).src_files = - curr_scope.get_var_value>(name_var); + current_scope.get_var_value(tmp_str_prefix).src_files = + current_scope.get_var_value>(name_var); } else if (tmp_str_postfix == PRJ_VAR_NAME_UTEMPLATES) { - if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 4) + if (current_scope.what_type(tmp_str_prefix) != 5 || current_scope.what_type(name_var) != 4) return; - curr_scope.get_var_value(tmp_str_prefix).vec_templates = - curr_scope.get_var_value>(name_var); + current_scope.get_var_value(tmp_str_prefix).vec_templates = + current_scope.get_var_value>(name_var); } else if (tmp_str_postfix == PRJ_VAR_NAME_UITTEMPLATES) { - if (curr_scope.what_type(tmp_str_prefix) != 5 || curr_scope.what_type(name_var) != 1) + if (current_scope.what_type(tmp_str_prefix) != 5 || current_scope.what_type(name_var) != 1) return; - curr_scope.get_var_value(tmp_str_prefix).use_it_templates = - curr_scope.get_var_value(name_var); + current_scope.get_var_value(tmp_str_prefix).use_it_templates = + current_scope.get_var_value(name_var); } else if (tmp_str_postfix == TRG_VAR_NAME_NPROJECT) { - if (curr_scope.what_type(tmp_str_prefix) != 6 || curr_scope.what_type(name_var) != 2) + if (current_scope.what_type(tmp_str_prefix) != 6 || current_scope.what_type(name_var) != 2) return; - curr_scope.get_var_value(tmp_str_prefix).prj->name_project = - curr_scope.get_var_value(name_var); + current_scope.get_var_value(tmp_str_prefix).prj->name_project = + current_scope.get_var_value(name_var); } else if (tmp_str_postfix == TRG_VAR_NAME_VER) { - if (curr_scope.what_type(tmp_str_prefix) != 6 || curr_scope.what_type(name_var) != 2) + if (current_scope.what_type(tmp_str_prefix) != 6 || current_scope.what_type(name_var) != 2) return; - curr_scope.get_var_value(tmp_str_prefix).version_target = - var::struct_sb::version(curr_scope.get_var_value(name_var)); + current_scope.get_var_value(tmp_str_prefix).version_target = + var::struct_sb::version(current_scope.get_var_value(name_var)); } else if (tmp_str_postfix == TRG_VAR_NAME_CFG) { - if (curr_scope.what_type(tmp_str_prefix) != 6 || curr_scope.what_type(name_var) != 1) + if (current_scope.what_type(tmp_str_prefix) != 6 || current_scope.what_type(name_var) != 1) return; - curr_scope.get_var_value(tmp_str_prefix).target_cfg = - (var::struct_sb::configuration)curr_scope.get_var_value(name_var); + current_scope.get_var_value(tmp_str_prefix).target_cfg = + (var::struct_sb::configuration)current_scope.get_var_value(name_var); } else if (tmp_str_postfix == TRG_VAR_NAME_TYPE_T) { - if (curr_scope.what_type(tmp_str_prefix) != 6 || curr_scope.what_type(name_var) != 1) + if (current_scope.what_type(tmp_str_prefix) != 6 || current_scope.what_type(name_var) != 1) return; - curr_scope.get_var_value(tmp_str_prefix).target_t = - (var::struct_sb::type_target)curr_scope.get_var_value(name_var); + current_scope.get_var_value(tmp_str_prefix).target_t = + (var::struct_sb::type_target)current_scope.get_var_value(name_var); } else if (tmp_str_postfix == TRG_VAR_NAME_NGENERATOR) { - if (curr_scope.what_type(tmp_str_prefix) != 6 || curr_scope.what_type(name_var) != 2) + if (current_scope.what_type(tmp_str_prefix) != 6 || current_scope.what_type(name_var) != 2) return; - curr_scope.get_var_value(tmp_str_prefix).name_generator = - curr_scope.get_var_value(name_var); + current_scope.get_var_value(tmp_str_prefix).name_generator = + current_scope.get_var_value(name_var); } else if (tmp_str_postfix == TRG_VAR_NAME_LLIBS) { - if (curr_scope.what_type(tmp_str_prefix) != 6 || curr_scope.what_type(name_var) != 1) + if (current_scope.what_type(tmp_str_prefix) != 6 || current_scope.what_type(name_var) != 1) return; - curr_scope.get_var_value(tmp_str_prefix).target_vec_libs = - curr_scope.get_var_value>(name_var); + current_scope.get_var_value(tmp_str_prefix).target_vec_libs = + current_scope.get_var_value>(name_var); } else { - if (curr_scope.what_type(tmp_str_prefix) != 5 && curr_scope.what_type(name_var) != 2) + if (current_scope.what_type(tmp_str_prefix) != 5 && current_scope.what_type(name_var) != 2) return; - auto prj = curr_scope.get_var_value(tmp_str_prefix); + auto prj = current_scope.get_var_value(tmp_str_prefix); auto it_field = prj.custom_ext_fields.find(tmp_str_postfix); if (it_field != prj.custom_ext_fields.end()) - it_field->second = curr_scope.get_var_value(name_var); + it_field->second = current_scope.get_var_value(name_var); } return; } @@ -159,126 +157,85 @@ static void update_cfg_struct(const std::string &name_var, var::scope &curr_scop } } -void sl_func::set(const std::vector &sub_expr, var::scope &curr_scope) { - if (sub_expr.size() == 0) +void sl_func::set(const expressions &expr_s, var::scope ¤t_scope) { + if (expr_s.size() == 0) return; - u32t index_var = curr_scope.what_type(sub_expr[0].token_of_subexpr[0].token_val); - if (sub_expr.size() == 1) { + u32t index_var = current_scope.what_type(expr_s[0].value); + if (expr_s.size() == 1) { if (index_var == 0) - (void)curr_scope.create_var(sub_expr[0].token_of_subexpr[0].token_val); + (void)current_scope.create_var(expr_s[0].value); } - else if (sub_expr.size() == 2) { - if (sub_expr[1].subexpr_t == subexpressions::type_subexpr::INT) { + else if (expr_s.size() == 2) { + if (expr_s[1].type == expression::expression_t::NUMBER) { if (index_var == 1) - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val) = - std::stoi(sub_expr[1].token_of_subexpr[0].token_val.c_str()); + current_scope.get_var_value(expr_s[0].value) = std::stoi(expr_s[1].value); else if (index_var == 3) - curr_scope.get_var_value>(sub_expr[0].token_of_subexpr[0].token_val) = { - std::stoi(sub_expr[1].token_of_subexpr[0].token_val.c_str())}; + current_scope.get_var_value>(expr_s[0].value) = {std::stoi(expr_s[1].value)}; else if (index_var == 0) - (void)curr_scope.create_var(sub_expr[0].token_of_subexpr[0].token_val, - std::stoll(sub_expr[1].token_of_subexpr[0].token_val.c_str())); - else - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + " Var - [" + - sub_expr[0].token_of_subexpr[0].token_val + "] is " + var::type_var_to_str(index_var) + "\n", - "003"); + (void)current_scope.create_var(expr_s[0].value, std::stoll(expr_s[1].value)); } - else if (sub_expr[1].subexpr_t == subexpressions::type_subexpr::STRING) { + else if (expr_s[1].type == expression::expression_t::STRING) { if (index_var == 2) - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val) = - sub_expr[1].token_of_subexpr[0].token_val; + current_scope.get_var_value(expr_s[0].value) = expr_s[1].value; else if (index_var == 4) - curr_scope.get_var_value>(sub_expr[0].token_of_subexpr[0].token_val) = { - sub_expr[1].token_of_subexpr[0].token_val}; + current_scope.get_var_value>(expr_s[0].value) = {expr_s[1].value}; else if (index_var == 0) - (void)curr_scope.create_var(sub_expr[0].token_of_subexpr[0].token_val, - sub_expr[1].token_of_subexpr[0].token_val); - else - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + " Var - [" + - sub_expr[0].token_of_subexpr[0].token_val + "] is " + var::type_var_to_str(index_var) + "\n", - "003"); + (void)current_scope.create_var(expr_s[0].value, expr_s[1].value); } } - else if (sub_expr.size() > 2) { - if (sub_expr[1].subexpr_t == subexpressions::type_subexpr::INT) { + else if (expr_s.size() > 2) { + if (expr_s[1].type == expression::expression_t::NUMBER) { std::vector vec_int_params; - vec_int_params.push_back(std::stoi(sub_expr[1].token_of_subexpr[0].token_val.c_str())); - for (u32t i = 2; i < sub_expr.size(); ++i) { - if (sub_expr[i].subexpr_t == subexpressions::type_subexpr::INT) - vec_int_params.push_back(std::stoi(sub_expr[i].token_of_subexpr[0].token_val.c_str())); + vec_int_params.push_back(std::stoi(expr_s[1].value)); + for (u32t i = 2; i < expr_s.size(); ++i) { + if (expr_s[i].type == expression::expression_t::NUMBER) + vec_int_params.push_back(std::stoi(expr_s[i].value)); } if (index_var == 0) - (void)curr_scope.create_var>(sub_expr[0].token_of_subexpr[0].token_val, - vec_int_params); + (void)current_scope.create_var>(expr_s[0].value, vec_int_params); else if (index_var == 3) - curr_scope.get_var_value>(sub_expr[0].token_of_subexpr[0].token_val) = vec_int_params; - else if (index_var == 1) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + " Var - [" + - sub_expr[0].token_of_subexpr[0].token_val + "] is int\n", - "002"); - else - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + " Var - [" + - sub_expr[0].token_of_subexpr[0].token_val + "] is " + var::type_var_to_str(index_var) + "\n", - "003"); + current_scope.get_var_value>(expr_s[0].value) = vec_int_params; } - else if (sub_expr[1].subexpr_t == subexpressions::type_subexpr::STRING) { + else if (expr_s[1].type == expression::expression_t::STRING) { std::vector vec_str_params; - vec_str_params.push_back(sub_expr[1].token_of_subexpr[0].token_val); - for (u32t i = 2; i < sub_expr.size(); ++i) { - if (sub_expr[i].subexpr_t == subexpressions::type_subexpr::STRING) - vec_str_params.push_back(sub_expr[i].token_of_subexpr[0].token_val); + vec_str_params.push_back(expr_s[1].value); + for (u32t i = 2; i < expr_s.size(); ++i) { + if (expr_s[i].type == expression::expression_t::STRING) + vec_str_params.push_back(expr_s[i].value); } if (index_var == 0) - (void)curr_scope.create_var>(sub_expr[0].token_of_subexpr[0].token_val, - vec_str_params); + (void)current_scope.create_var>(expr_s[0].value, vec_str_params); else if (index_var == 4) - curr_scope.get_var_value>(sub_expr[0].token_of_subexpr[0].token_val) = - vec_str_params; - else if (index_var == 2) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + " Var - [" + - sub_expr[0].token_of_subexpr[0].token_val + "] is string\n", - "002"); - else - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + " Var - [" + - sub_expr[0].token_of_subexpr[0].token_val + "] is " + var::type_var_to_str(index_var) + "\n", - "003"); + current_scope.get_var_value>(expr_s[0].value) = vec_str_params; } } // ?????? // if a variable is abstract ref to cfg structs - update_cfg_struct(sub_expr[0].token_of_subexpr[0].token_val, curr_scope); + update_cfg_struct(expr_s[0].value, current_scope); } -void sl_func::file(const std::vector &sub_expr, var::scope &curr_scope) { - if (std::stoi(sub_expr[1].token_of_subexpr[0].token_val) == 0) { +void sl_func::file(const expressions &expr_s, var::scope ¤t_scope) { + if (std::stoi(expr_s[1].value) == 0) { std::vector path_files; - for (u32t i = 2; i < sub_expr.size(); ++i) { - if (std::filesystem::exists(sub_expr[i].token_of_subexpr[0].token_val)) { - path_files.push_back(std::filesystem::absolute(sub_expr[i].token_of_subexpr[0].token_val).string()); + for (u32t i = 2; i < expr_s.size(); ++i) { + if (std::filesystem::exists(expr_s[i].value)) { + path_files.push_back(std::filesystem::absolute(expr_s[i].value).string()); continue; } - std::string tmp_path = sub_expr[i].token_of_subexpr[0].token_val; - std::string mask = sub_expr[i].token_of_subexpr[0].token_val; - u32t it = tmp_path.find_last_of("/\\"); + std::string tmp_path = expr_s[i].value; + std::string mask = expr_s[i].value; + u32t it = tmp_path.find_last_of("/\\"); if (it != tmp_path.npos) { tmp_path.erase(it); mask = std::filesystem::absolute(mask).string(); if (!std::filesystem::is_directory(tmp_path)) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[i].token_of_subexpr[0]) + - " Directory does not exist\n", - "003"); + _log << bwtools::fatal + << (log_message(log_type::fatal) << "Directory does not exist: " << tmp_path); } else { tmp_path = std::filesystem::current_path().string(); - mask = tmp_path + "/" + mask; + mask = tmp_path + "/" + mask; } std::vector tmp_path_files, tmp_path_files_o; for (const auto &it_path : std::filesystem::directory_iterator(tmp_path)) @@ -289,159 +246,150 @@ void sl_func::file(const std::vector &sub_expr, var::s } if (path_files.size() == 1) - curr_scope.create_var(sub_expr[0].token_of_subexpr[0].token_val, path_files[0]); + current_scope.create_var(expr_s[0].value, path_files[0]); else - curr_scope.create_var>(sub_expr[0].token_of_subexpr[0].token_val, path_files); + current_scope.create_var>(expr_s[0].value, path_files); } } -void sl_func::project(const std::vector &sub_expr, var::scope &curr_scope) { - var::struct_sb::project &prj_ref = - curr_scope.create_var(sub_expr[0].token_of_subexpr[0].token_val); - prj_ref.name_project = sub_expr[0].token_of_subexpr[0].token_val; - prj_ref.language = sub_expr[1].token_of_subexpr[0].token_val; - for (u32t i = 2; i < sub_expr.size(); ++i) - prj_ref.src_files.push_back(sub_expr[i].token_of_subexpr[0].token_val); +void sl_func::project(const expressions &expr_s, var::scope ¤t_scope) { + var::struct_sb::project &prj_ref = current_scope.create_var(expr_s[0].value); + prj_ref.name_project = expr_s[0].value; + prj_ref.language = expr_s[1].value; + for (u32t i = 2; i < expr_s.size(); ++i) + prj_ref.src_files.push_back(expr_s[i].value); // ??????? - I don't know if this helper function is needed - if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) { - if (!curr_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_LANG, prj_ref.language)) - prj_ref.language = curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_LANG); - if (!curr_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_VER, - prj_ref.version_project.get_str_version())) - prj_ref.version_project = - var::struct_sb::version(curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_VER)); - - if (!curr_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_C, - prj_ref.dflags_compiler)) + if (current_scope.what_type(DECL_VAR_STRUCT) == 1 && current_scope.get_var_value(DECL_VAR_STRUCT) > 0) { + if (!current_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_LANG, prj_ref.language)) + prj_ref.language = current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_LANG); + if (!current_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_VER, + prj_ref.version_project.get_str_version())) + prj_ref.version_project = var::struct_sb::version( + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_VER)); + + if (!current_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_C, + prj_ref.dflags_compiler)) prj_ref.dflags_compiler = - curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_C); - if (!curr_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_L, - prj_ref.dflags_linker)) - prj_ref.dflags_linker = curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_L); - if (!curr_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_C, - prj_ref.rflags_compiler)) + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_C); + if (!current_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_L, + prj_ref.dflags_linker)) + prj_ref.dflags_linker = + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_L); + if (!current_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_C, + prj_ref.rflags_compiler)) prj_ref.rflags_compiler = - curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_C); - if (!curr_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_L, - prj_ref.rflags_linker)) - prj_ref.rflags_linker = curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_L); - if (!curr_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_PTH_C, prj_ref.path_compiler)) - prj_ref.path_compiler = curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_PTH_C); - if (!curr_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_PTH_L, prj_ref.path_linker)) - prj_ref.path_linker = curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_PTH_L); - if (!curr_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_STD_C, prj_ref.standart_c)) - prj_ref.standart_c = curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_STD_C); - if (!curr_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_STD_CPP, prj_ref.standart_cpp)) - prj_ref.standart_cpp = curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_STD_CPP); - if (!curr_scope.try_create_var>(prj_ref.name_project + PRJ_VAR_NAME_SRC_FILES, - prj_ref.src_files)) + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_C); + if (!current_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_L, + prj_ref.rflags_linker)) + prj_ref.rflags_linker = + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_L); + if (!current_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_PTH_C, + prj_ref.path_compiler)) + prj_ref.path_compiler = current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_PTH_C); + if (!current_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_PTH_L, prj_ref.path_linker)) + prj_ref.path_linker = current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_PTH_L); + if (!current_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_STD_C, prj_ref.standart_c)) + prj_ref.standart_c = current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_STD_C); + if (!current_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_STD_CPP, prj_ref.standart_cpp)) + prj_ref.standart_cpp = current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_STD_CPP); + if (!current_scope.try_create_var>(prj_ref.name_project + PRJ_VAR_NAME_SRC_FILES, + prj_ref.src_files)) prj_ref.src_files = - curr_scope.get_var_value>(prj_ref.name_project + PRJ_VAR_NAME_SRC_FILES); - if (!curr_scope.try_create_var>(prj_ref.name_project + PRJ_VAR_NAME_UTEMPLATES, - prj_ref.vec_templates)) + current_scope.get_var_value>(prj_ref.name_project + PRJ_VAR_NAME_SRC_FILES); + if (!current_scope.try_create_var>(prj_ref.name_project + PRJ_VAR_NAME_UTEMPLATES, + prj_ref.vec_templates)) prj_ref.vec_templates = - curr_scope.get_var_value>(prj_ref.name_project + PRJ_VAR_NAME_UTEMPLATES); - if (!curr_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_UITTEMPLATES, - prj_ref.use_it_templates)) - prj_ref.use_it_templates = curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_UITTEMPLATES); + current_scope.get_var_value>(prj_ref.name_project + PRJ_VAR_NAME_UTEMPLATES); + if (!current_scope.try_create_var(prj_ref.name_project + PRJ_VAR_NAME_UITTEMPLATES, + prj_ref.use_it_templates)) + prj_ref.use_it_templates = + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_UITTEMPLATES); } } -void sl_func::executable(const std::vector &sub_expr, var::scope &curr_scope) { - if (curr_scope.what_type(sub_expr[2].token_of_subexpr[0].token_val) != 5) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[2].token_of_subexpr[0]) + - " Var id of struct(expected project): " + sub_expr[2].token_of_subexpr[0].token_val + "\n", - "001"); - var::struct_sb::target &trg_ref = - curr_scope.create_var(sub_expr[0].token_of_subexpr[0].token_val); - - trg_ref.name_target = sub_expr[0].token_of_subexpr[0].token_val; - trg_ref.prj = std::shared_ptr( - (var::struct_sb::project *)&curr_scope.get_var_value( - sub_expr[2].token_of_subexpr[0].token_val), +void sl_func::executable(const expressions &expr_s, var::scope ¤t_scope) { + if (current_scope.what_type(expr_s[2].value) != 5) + _log << bwtools::fatal << (log_message(log_type::fatal) << "Expected var project: " << expr_s[2].value); + + var::struct_sb::target &trg_ref = current_scope.create_var(expr_s[0].value); + + trg_ref.name_target = expr_s[0].value; + trg_ref.prj = std::shared_ptr( + (var::struct_sb::project *)¤t_scope.get_var_value(expr_s[2].value), [](const var::struct_sb::project *) {}); - trg_ref.target_cfg = (var::struct_sb::configuration)std::stoi(sub_expr[1].token_of_subexpr[0].token_val); + trg_ref.target_cfg = (var::struct_sb::configuration)std::stoi(expr_s[1].value); trg_ref.version_target = var::struct_sb::version(0, 0, 0); // ??????? - I don't know if this helper function is needed - if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) { - if (!curr_scope.try_create_var(trg_ref.name_target + TRG_VAR_NAME_NPROJECT, - trg_ref.prj->name_project)) + if (current_scope.what_type(DECL_VAR_STRUCT) == 1 && current_scope.get_var_value(DECL_VAR_STRUCT) > 0) { + if (!current_scope.try_create_var(trg_ref.name_target + TRG_VAR_NAME_NPROJECT, + trg_ref.prj->name_project)) trg_ref.prj->name_project = - curr_scope.get_var_value(trg_ref.name_target + TRG_VAR_NAME_NPROJECT); - if (!curr_scope.try_create_var(trg_ref.name_target + TRG_VAR_NAME_VER, - trg_ref.version_target.get_str_version())) - trg_ref.version_target = - var::struct_sb::version(curr_scope.get_var_value(trg_ref.name_target + TRG_VAR_NAME_VER)); - if (!curr_scope.try_create_var(trg_ref.name_target + TRG_VAR_NAME_CFG, (i32t)trg_ref.target_cfg)) - trg_ref.target_cfg = - (var::struct_sb::configuration)curr_scope.get_var_value(trg_ref.name_target + TRG_VAR_NAME_CFG); - if (!curr_scope.try_create_var(trg_ref.name_target + TRG_VAR_NAME_TYPE_T, (i32t)trg_ref.target_t)) - trg_ref.target_t = - (var::struct_sb::type_target)curr_scope.get_var_value(trg_ref.name_target + TRG_VAR_NAME_TYPE_T); - if (!curr_scope.try_create_var(trg_ref.name_target + TRG_VAR_NAME_NGENERATOR, - trg_ref.name_generator)) + current_scope.get_var_value(trg_ref.name_target + TRG_VAR_NAME_NPROJECT); + if (!current_scope.try_create_var(trg_ref.name_target + TRG_VAR_NAME_VER, + trg_ref.version_target.get_str_version())) + trg_ref.version_target = var::struct_sb::version( + current_scope.get_var_value(trg_ref.name_target + TRG_VAR_NAME_VER)); + if (!current_scope.try_create_var(trg_ref.name_target + TRG_VAR_NAME_CFG, (i32t)trg_ref.target_cfg)) + trg_ref.target_cfg = (var::struct_sb::configuration)current_scope.get_var_value(trg_ref.name_target + + TRG_VAR_NAME_CFG); + if (!current_scope.try_create_var(trg_ref.name_target + TRG_VAR_NAME_TYPE_T, (i32t)trg_ref.target_t)) + trg_ref.target_t = (var::struct_sb::type_target)current_scope.get_var_value(trg_ref.name_target + + TRG_VAR_NAME_TYPE_T); + if (!current_scope.try_create_var(trg_ref.name_target + TRG_VAR_NAME_NGENERATOR, + trg_ref.name_generator)) trg_ref.name_generator = - curr_scope.get_var_value(trg_ref.name_target + TRG_VAR_NAME_NGENERATOR); - if (!curr_scope.try_create_var>(trg_ref.name_target + TRG_VAR_NAME_LLIBS, - trg_ref.target_vec_libs)) + current_scope.get_var_value(trg_ref.name_target + TRG_VAR_NAME_NGENERATOR); + if (!current_scope.try_create_var>(trg_ref.name_target + TRG_VAR_NAME_LLIBS, + trg_ref.target_vec_libs)) trg_ref.target_vec_libs = - curr_scope.get_var_value>(trg_ref.name_target + TRG_VAR_NAME_LLIBS); + current_scope.get_var_value>(trg_ref.name_target + TRG_VAR_NAME_LLIBS); } } -void sl_func::link_lib(const std::vector &sub_expr, var::scope &curr_scope) { - if (curr_scope.what_type(sub_expr[0].token_of_subexpr[0].token_val) != 6) - throw interpreter::realtime_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " Var id of struct(expected target): " + sub_expr[0].token_of_subexpr[0].token_val + "\n", - "003"); - var::struct_sb::target &trg_ref = - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); - for (u32t i = 1; i < sub_expr.size(); ++i) - trg_ref.target_vec_libs.push_back(sub_expr[i].token_of_subexpr[0].token_val); - - if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) { - if (curr_scope.what_type(trg_ref.name_target + TRG_VAR_NAME_LLIBS) == 4) { - curr_scope.get_var_value>(trg_ref.name_target + TRG_VAR_NAME_LLIBS) = +void sl_func::link_lib(const expressions &expr_s, var::scope ¤t_scope) { + if (current_scope.what_type(expr_s[0].value) != 6) + _log << bwtools::fatal << (log_message(log_type::fatal) << "Expected var target: " << expr_s[2].value); + + var::struct_sb::target &trg_ref = current_scope.get_var_value(expr_s[0].value); + + for (u32t i = 1; i < expr_s.size(); ++i) + trg_ref.target_vec_libs.push_back(expr_s[i].value); + + if (current_scope.what_type(DECL_VAR_STRUCT) == 1 && current_scope.get_var_value(DECL_VAR_STRUCT) > 0) { + if (current_scope.what_type(trg_ref.name_target + TRG_VAR_NAME_LLIBS) == 4) { + current_scope.get_var_value>(trg_ref.name_target + TRG_VAR_NAME_LLIBS) = trg_ref.target_vec_libs; } else - curr_scope.create_var>(trg_ref.name_target + TRG_VAR_NAME_LLIBS, - trg_ref.target_vec_libs); + current_scope.create_var>(trg_ref.name_target + TRG_VAR_NAME_LLIBS, + trg_ref.target_vec_libs); } } -void sl_func::exp_data(const std::vector &sub_expr, var::scope &curr_scope) { - interpreter::interpreter_exec::config tmp_conf; - tmp_conf.filename_interp = sub_expr[0].token_of_subexpr[0].token_val.c_str(); - tmp_conf.use_external_scope = 1; - interpreter::interpreter_exec tmp_interpreter; - tmp_interpreter.set_config(tmp_conf); - tmp_interpreter.set_external_scope(&curr_scope); - tmp_interpreter.build_aef(); +void sl_func::exp_data(const expressions &expr_s, var::scope ¤t_scope) { + interpreter tmp_interpreter(expr_s[0].value); + tmp_interpreter.set_external_scope(¤t_scope); } -void sl_func::cmd(const std::vector &sub_expr, var::scope &curr_scope) { - u32t val = std::stoi(sub_expr[0].token_of_subexpr[0].token_val.c_str()); +void sl_func::cmd(const expressions &expr_s, var::scope ¤t_scope) { + u32t val = std::stoi(expr_s[0].value); if (!val) - curr_scope.call_cmd.add_call_before(sub_expr[1].token_of_subexpr[0].token_val); + current_scope.call_cmd.add_call_before(expr_s[1].value); else - curr_scope.call_cmd.add_call_after(sub_expr[1].token_of_subexpr[0].token_val); + current_scope.call_cmd.add_call_after(expr_s[1].value); } -void sl_func::debug(const std::vector &sub_expr, var::scope &curr_scope) { +void sl_func::debug(const expressions &expr_s, var::scope ¤t_scope) { std::string str_out; - for (u32t i = 0; i < sub_expr.size(); ++i) - str_out += sub_expr[i].token_of_subexpr[0].token_val + " "; - assist << str_out; + for (u32t i = 0; i < expr_s.size(); ++i) + str_out += expr_s[i].value + " "; + _log << bwtools::message << (log_message(log_type::msg) << str_out); } -void sl_func::debug_struct(const std::vector &sub_expr, var::scope &curr_scope) { - std::string out_str; - u32t ind = curr_scope.what_type(sub_expr[0].token_of_subexpr[0].token_val); +void sl_func::debug_struct(const expressions &expr_s, var::scope ¤t_scope) { + std::string str_out; + u32t ind = current_scope.what_type(expr_s[0].value); if (ind == 5) { - var::struct_sb::project &prj_ref = - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); - out_str = "Name Project: " + prj_ref.name_project + "\nVersion: " + prj_ref.version_project.get_str_version() + + var::struct_sb::project &prj_ref = current_scope.get_var_value(expr_s[0].value); + str_out = "Name Project: " + prj_ref.name_project + "\nVersion: " + prj_ref.version_project.get_str_version() + "\nLang: " + prj_ref.language + "\nCompiler: " + prj_ref.path_compiler + "\nLinker: " + prj_ref.path_linker + "\nDebug Flags Compiler: " + prj_ref.dflags_compiler + "\nRelease Flags Compiler: " + prj_ref.rflags_compiler + @@ -450,210 +398,187 @@ void sl_func::debug_struct(const std::vector &sub_expr "\nStandart C: " + std::to_string(prj_ref.standart_c) + "\nStandart C++: " + std::to_string(prj_ref.standart_cpp) + "\n------\nSRC_FILES: \n"; for (u32t i = 0; i < prj_ref.src_files.size(); ++i) { - out_str += prj_ref.src_files[i]; + str_out += prj_ref.src_files[i]; if (i != prj_ref.src_files.size() - 1) - out_str += ", "; + str_out += ", "; } - out_str += "\n\nWill templates be used? - " + std::to_string(prj_ref.use_it_templates) + "\nTemplates: \n"; + str_out += "\n\nWill templates be used? - " + std::to_string(prj_ref.use_it_templates) + "\nTemplates: \n"; for (u32t i = 0; i < prj_ref.vec_templates.size(); ++i) { - out_str += prj_ref.vec_templates[i]; + str_out += prj_ref.vec_templates[i]; if (i != prj_ref.vec_templates.size() - 1) - out_str += ", "; + str_out += ", "; } } else if (ind == 6) { - var::struct_sb::target &trg_ref = - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); - out_str = "Name Target: " + trg_ref.name_target + "\nVersion: " + trg_ref.version_target.get_str_version() + + var::struct_sb::target &trg_ref = current_scope.get_var_value(expr_s[0].value); + str_out = "Name Target: " + trg_ref.name_target + "\nVersion: " + trg_ref.version_target.get_str_version() + "\nName Project: " + trg_ref.prj->name_project + "\nType Build: " + target_t_str(trg_ref.target_t) + "\nConfiguration: " + cfg_str(trg_ref.target_cfg) + "\nLibs: \n"; for (u32t i = 0; i < trg_ref.target_vec_libs.size(); ++i) { - out_str += trg_ref.target_vec_libs[i]; + str_out += trg_ref.target_vec_libs[i]; if (i != trg_ref.target_vec_libs.size() - 1) - out_str += ", "; + str_out += ", "; } } - assist << out_str; + _log << bwtools::message << (log_message(log_type::msg) << str_out); } -void sl_func::flags_compiler(const std::vector &sub_expr, var::scope &curr_scope) { - if (curr_scope.what_type(sub_expr[0].token_of_subexpr[0].token_val) != 5) - throw interpreter::realtime_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " Var id of struct(expected project): " + sub_expr[0].token_of_subexpr[0].token_val + "\n", - "003"); - var::struct_sb::project &prj_ref = - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); +void sl_func::flags_compiler(const expressions &expr_s, var::scope ¤t_scope) { + if (current_scope.what_type(expr_s[0].value) != 5) + _log << bwtools::fatal << (log_message(log_type::fatal) << "Expected var project: " << expr_s[0].value); + + var::struct_sb::project &prj_ref = current_scope.get_var_value(expr_s[0].value); var::struct_sb::configuration tmp_cfg; - if ((tmp_cfg = (var::struct_sb::configuration)std::stoi(sub_expr[1].token_of_subexpr[0].token_val.c_str())) == - var::struct_sb::configuration::RELEASE) - for (u32t i = 2; i < sub_expr.size(); ++i) { - prj_ref.rflags_compiler += sub_expr[i].token_of_subexpr[0].token_val + " "; + + if ((tmp_cfg = (var::struct_sb::configuration)std::stoi(expr_s[1].value)) == var::struct_sb::configuration::RELEASE) + for (u32t i = 2; i < expr_s.size(); ++i) { + prj_ref.rflags_compiler += expr_s[i].value + " "; } else - for (u32t i = 2; i < sub_expr.size(); ++i) { - prj_ref.dflags_compiler += sub_expr[i].token_of_subexpr[0].token_val + " "; + for (u32t i = 2; i < expr_s.size(); ++i) { + prj_ref.dflags_compiler += expr_s[i].value + " "; } - if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) + if (current_scope.what_type(DECL_VAR_STRUCT) == 1 && current_scope.get_var_value(DECL_VAR_STRUCT) > 0) if (tmp_cfg == var::struct_sb::configuration::DEBUG) - if (curr_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_C) == 2) { - curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_C) = + if (current_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_C) == 2) { + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_C) = prj_ref.dflags_compiler; } else - curr_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_C, - prj_ref.dflags_compiler); + current_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_C, + prj_ref.dflags_compiler); else if (tmp_cfg == var::struct_sb::configuration::RELEASE) - if (curr_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_C) == 2) { - curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_C) = + if (current_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_C) == 2) { + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_C) = prj_ref.rflags_compiler; } else - curr_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_C, - prj_ref.rflags_compiler); + current_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_C, + prj_ref.rflags_compiler); } -void sl_func::flags_linker(const std::vector &sub_expr, var::scope &curr_scope) { - if (curr_scope.what_type(sub_expr[0].token_of_subexpr[0].token_val) != 5) - throw interpreter::realtime_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " Var id of struct(expected project): " + sub_expr[0].token_of_subexpr[0].token_val + "\n", - "003"); - var::struct_sb::project &prj_ref = - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); +void sl_func::flags_linker(const expressions &expr_s, var::scope ¤t_scope) { + if (current_scope.what_type(expr_s[0].value) != 5) + _log << bwtools::fatal << (log_message(log_type::fatal) << "Expected var project: " << expr_s[0].value); + + var::struct_sb::project &prj_ref = current_scope.get_var_value(expr_s[0].value); var::struct_sb::configuration tmp_cfg; - if ((tmp_cfg = (var::struct_sb::configuration)std::stoi(sub_expr[1].token_of_subexpr[0].token_val.c_str())) == - var::struct_sb::configuration::RELEASE) - for (u32t i = 2; i < sub_expr.size(); ++i) { - prj_ref.rflags_linker += sub_expr[i].token_of_subexpr[0].token_val + " "; + + if ((tmp_cfg = (var::struct_sb::configuration)std::stoi(expr_s[1].value)) == var::struct_sb::configuration::RELEASE) + for (u32t i = 2; i < expr_s.size(); ++i) { + prj_ref.rflags_linker += expr_s[i].value + " "; } else - for (u32t i = 2; i < sub_expr.size(); ++i) { - prj_ref.dflags_linker += sub_expr[i].token_of_subexpr[0].token_val + " "; + for (u32t i = 2; i < expr_s.size(); ++i) { + prj_ref.dflags_linker += expr_s[i].value + " "; } - if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) + if (current_scope.what_type(DECL_VAR_STRUCT) == 1 && current_scope.get_var_value(DECL_VAR_STRUCT) > 0) if (tmp_cfg == var::struct_sb::configuration::DEBUG) - if (curr_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_L) == 2) { - curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_L) = + if (current_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_L) == 2) { + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_L) = prj_ref.dflags_linker; } else - curr_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_L, prj_ref.dflags_linker); + current_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_DFLAGS_L, + prj_ref.dflags_linker); else if (tmp_cfg == var::struct_sb::configuration::RELEASE) - if (curr_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_L) == 2) { - curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_L) = + if (current_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_L) == 2) { + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_L) = prj_ref.rflags_linker; } else - curr_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_L, prj_ref.dflags_linker); + current_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_RFLAGS_L, + prj_ref.dflags_linker); } -void sl_func::path_compiler(const std::vector &sub_expr, var::scope &curr_scope) { - if (curr_scope.what_type(sub_expr[0].token_of_subexpr[0].token_val) != 5) - throw interpreter::realtime_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " Var id of struct(expected project): " + sub_expr[0].token_of_subexpr[0].token_val + "\n", - "003"); - var::struct_sb::project &prj_ref = - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); - prj_ref.path_compiler = sub_expr[1].token_of_subexpr[0].token_val; - - if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) - if (curr_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_PTH_C) == 2) { - curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_PTH_C) = prj_ref.path_compiler; +void sl_func::path_compiler(const expressions &expr_s, var::scope ¤t_scope) { + if (current_scope.what_type(expr_s[0].value) != 5) + _log << bwtools::fatal << (log_message(log_type::fatal) << "Expected var project: " << expr_s[0].value); + + var::struct_sb::project &prj_ref = current_scope.get_var_value(expr_s[0].value); + prj_ref.path_compiler = expr_s[1].value; + + if (current_scope.what_type(DECL_VAR_STRUCT) == 1 && current_scope.get_var_value(DECL_VAR_STRUCT) > 0) + if (current_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_PTH_C) == 2) { + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_PTH_C) = prj_ref.path_compiler; } else - curr_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_PTH_C, prj_ref.path_compiler); + current_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_PTH_C, prj_ref.path_compiler); } -void sl_func::path_linker(const std::vector &sub_expr, var::scope &curr_scope) { - if (curr_scope.what_type(sub_expr[0].token_of_subexpr[0].token_val) != 5) - throw interpreter::realtime_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " Var id of struct(expected project): " + sub_expr[0].token_of_subexpr[0].token_val + "\n", - "003"); - var::struct_sb::project &prj_ref = - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); - prj_ref.path_linker = sub_expr[1].token_of_subexpr[0].token_val; - - if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) - if (curr_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_PTH_C) == 2) { - curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_PTH_C) = prj_ref.path_linker; +void sl_func::path_linker(const expressions &expr_s, var::scope ¤t_scope) { + if (current_scope.what_type(expr_s[0].value) != 5) + _log << bwtools::fatal << (log_message(log_type::fatal) << "Expected var project: " << expr_s[0].value); + + var::struct_sb::project &prj_ref = current_scope.get_var_value(expr_s[0].value); + prj_ref.path_linker = expr_s[1].value; + + if (current_scope.what_type(DECL_VAR_STRUCT) == 1 && current_scope.get_var_value(DECL_VAR_STRUCT) > 0) + if (current_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_PTH_C) == 2) { + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_PTH_C) = prj_ref.path_linker; } else - curr_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_PTH_C, prj_ref.path_linker); + current_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_PTH_C, prj_ref.path_linker); } -void sl_func::standart_c(const std::vector &sub_expr, var::scope &curr_scope) { - if (curr_scope.what_type(sub_expr[0].token_of_subexpr[0].token_val) != 5) - throw interpreter::realtime_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " Var id of struct(expected project): " + sub_expr[0].token_of_subexpr[0].token_val + "\n", - "003"); - var::struct_sb::project &prj_ref = - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); - prj_ref.standart_c = std::stoi(sub_expr[1].token_of_subexpr[0].token_val.c_str()); - if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) - if (curr_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_STD_C) == 1) { - curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_STD_C) = prj_ref.standart_c; +void sl_func::standart_c(const expressions &expr_s, var::scope ¤t_scope) { + if (current_scope.what_type(expr_s[0].value) != 5) + _log << bwtools::fatal << (log_message(log_type::fatal) << "Expected var project: " << expr_s[0].value); + + var::struct_sb::project &prj_ref = current_scope.get_var_value(expr_s[0].value); + prj_ref.standart_c = std::stoi(expr_s[1].value); + + if (current_scope.what_type(DECL_VAR_STRUCT) == 1 && current_scope.get_var_value(DECL_VAR_STRUCT) > 0) + if (current_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_STD_C) == 1) { + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_STD_C) = prj_ref.standart_c; } else - curr_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_STD_C, prj_ref.standart_c); + current_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_STD_C, prj_ref.standart_c); } -void sl_func::standart_cpp(const std::vector &sub_expr, var::scope &curr_scope) { - if (curr_scope.what_type(sub_expr[0].token_of_subexpr[0].token_val) != 5) - throw interpreter::realtime_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " Var id of struct(expected project): " + sub_expr[0].token_of_subexpr[0].token_val + "\n", - "003"); - var::struct_sb::project &prj_ref = - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); - prj_ref.standart_cpp = std::stoi(sub_expr[1].token_of_subexpr[0].token_val.c_str()); - if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) - if (curr_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_STD_CPP) == 1) { - curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_STD_CPP) = prj_ref.standart_c; +void sl_func::standart_cpp(const expressions &expr_s, var::scope ¤t_scope) { + if (current_scope.what_type(expr_s[0].value) != 5) + _log << bwtools::fatal << (log_message(log_type::fatal) << "Expected var project: " << expr_s[0].value); + + var::struct_sb::project &prj_ref = current_scope.get_var_value(expr_s[0].value); + prj_ref.standart_cpp = std::stoi(expr_s[1].value); + + if (current_scope.what_type(DECL_VAR_STRUCT) == 1 && current_scope.get_var_value(DECL_VAR_STRUCT) > 0) + if (current_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_STD_CPP) == 1) { + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_STD_CPP) = prj_ref.standart_c; } else - curr_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_STD_CPP, prj_ref.standart_c); + current_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_STD_CPP, prj_ref.standart_c); } -void sl_func::lang(const std::vector &sub_expr, var::scope &curr_scope) { - if (curr_scope.what_type(sub_expr[0].token_of_subexpr[0].token_val) != 5) - throw interpreter::realtime_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " Var id of struct(expected project): " + sub_expr[0].token_of_subexpr[0].token_val + "\n", - "003"); - var::struct_sb::project &prj_ref = - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); - prj_ref.language = sub_expr[1].token_of_subexpr[0].token_val; - if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) - if (curr_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_LANG) == 1) - curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_LANG) = prj_ref.language; +void sl_func::lang(const expressions &expr_s, var::scope ¤t_scope) { + if (current_scope.what_type(expr_s[0].value) != 5) + _log << bwtools::fatal << (log_message(log_type::fatal) << "Expected var project: " << expr_s[0].value); + + var::struct_sb::project &prj_ref = current_scope.get_var_value(expr_s[0].value); + prj_ref.language = expr_s[1].value; + + if (current_scope.what_type(DECL_VAR_STRUCT) == 1 && current_scope.get_var_value(DECL_VAR_STRUCT) > 0) + if (current_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_LANG) == 1) + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_LANG) = prj_ref.language; else - curr_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_LANG, prj_ref.language); + current_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_LANG, prj_ref.language); } -void sl_func::generator(const std::vector &sub_expr, var::scope &curr_scope) { - if (curr_scope.what_type(sub_expr[0].token_of_subexpr[0].token_val) != 6) - throw interpreter::realtime_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " Var id of struct(expected target): " + sub_expr[0].token_of_subexpr[0].token_val + "\n", - "003"); - var::struct_sb::target &trg_ref = - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); - trg_ref.name_generator = sub_expr[1].token_of_subexpr[0].token_val; +void sl_func::generator(const expressions &expr_s, var::scope ¤t_scope) { + if (current_scope.what_type(expr_s[0].value) != 6) + _log << bwtools::fatal << (log_message(log_type::fatal) << "Expected var project: " << expr_s[0].value); + + var::struct_sb::target &trg_ref = current_scope.get_var_value(expr_s[0].value); + trg_ref.name_generator = expr_s[1].value; } -void sl_func::add_param_template(const std::vector &sub_expr, var::scope &curr_scope) { - if (curr_scope.what_type(sub_expr[1].token_of_subexpr[0].token_val) != 2) - throw interpreter::realtime_excp(parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " Global template arguments must be of type string: " + - sub_expr[0].token_of_subexpr[0].token_val + "\n", - "003"); - curr_scope.create_var>( - sub_expr[0].token_of_subexpr[0].token_val, - {sub_expr[0].token_of_subexpr[0].token_val, - curr_scope.get_var_value(sub_expr[1].token_of_subexpr[0].token_val)}); +void sl_func::add_param_template(const expressions &expr_s, var::scope ¤t_scope) { + if (current_scope.what_type(expr_s[1].value) != 2) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "Global template arguments must be of type string: " << expr_s[0].value); + current_scope.create_var>( + expr_s[0].value, {expr_s[0].value, current_scope.get_var_value(expr_s[1].value)}); } -void sl_func::create_templates(const std::vector &sub_expr, var::scope &curr_scope) { +void sl_func::create_templates(const expressions &expr_s, var::scope ¤t_scope) { std::string tmp_param; std::array name_field_target = { @@ -666,11 +591,11 @@ void sl_func::create_templates(const std::vector &sub_ var::struct_sb::template_command tcmd_tmp; var::struct_sb::template_command::arg arg_tmp; - tcmd_tmp.name = sub_expr[0].token_of_subexpr[0].token_val; + tcmd_tmp.name = expr_s[0].value; bool defined_template = 0; - bool op_close_acp_param = 0; + bool op_close_acp_param = 0; bool op_minus_and_next_arrow = 0; bool colon = 0; @@ -679,32 +604,28 @@ void sl_func::create_templates(const std::vector &sub_ // To access internal parameters passed to the template // <{SMT_PARAMETR}> - bool used_internal_param = 0; + bool used_internal_param = 0; bool was_close_used_internal_param = 0; bool op_comma = 0; // Regular line // <'string'> - bool op_quote = 0; + bool op_quote = 0; bool was_close_quote = 0; // To access the fields of the current target during assembly, to obtain its information // <[NAME_FIELD_TARGET_STRCTURE]> - bool op_target_hand_field = 0; + bool op_target_hand_field = 0; bool was_close_op_target_hand = 0; bool is_name_features_bs = 0; bool was_sep = 0; - for (u32t i = 0; i < sub_expr[1].token_of_subexpr[0].token_val.size(); ++i) { - - if ((sub_expr[1].token_of_subexpr[0].token_val[i] == ' ' || - sub_expr[1].token_of_subexpr[0].token_val[i] == '\n' || - sub_expr[1].token_of_subexpr[0].token_val[i] == '\t') && - !op_quote) { + for (u32t i = 0; i < expr_s[1].value.size(); ++i) { + if ((expr_s[1].value[i] == ' ' || expr_s[1].value[i] == '\n' || expr_s[1].value[i] == '\t') && !op_quote) { // te xt <- it is forbidden if (!tmp_param.empty()) was_sep = 1; @@ -712,108 +633,91 @@ void sl_func::create_templates(const std::vector &sub_ was_sep = 0; continue; } - else if ((op_quote && sub_expr[1].token_of_subexpr[0].token_val[i] != '\'') || - (is_name_features_bs && (sub_expr[1].token_of_subexpr[0].token_val[i] == ':' || - isdigit(sub_expr[1].token_of_subexpr[0].token_val[i]) || - isalpha(sub_expr[1].token_of_subexpr[0].token_val[i])))) + else if ((op_quote && expr_s[1].value[i] != '\'') || + (is_name_features_bs && + (expr_s[1].value[i] == ':' || isdigit(expr_s[1].value[i]) || isalpha(expr_s[1].value[i])))) goto curr_sym; - if (sub_expr[1].token_of_subexpr[0].token_val[i] == '(') { + if (expr_s[1].value[i] == '(') { if (defined_template) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " Unexpected operator of parameter enum of template\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "Unexpected operator of parameter enum of template: " << expr_s[1].value); else if (tmp_param.empty()) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The name of the call component is empty: " + tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "The name of the call component is empty(" << tmp_param << "): " << expr_s[1].value); else if (!tcmd_tmp.name_call_component.empty()) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The name of the call component that already exists: " + tmp_param + "\n", - "004"); - else if (curr_scope.what_type(tmp_param) != 8) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The specified call component does not exist: " + tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) << "The name of the call component that already exists(" + << tmp_param << "): " << expr_s[1].value); + else if (current_scope.what_type(tmp_param) != 8) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "The specified call component does not exist(" << tmp_param << "): " << expr_s[1].value); + tcmd_tmp.name_call_component = tmp_param; tmp_param.clear(); - defined_template = 1; + defined_template = 1; op_close_acp_param = 1; continue; } - else if (sub_expr[1].token_of_subexpr[0].token_val[i] == ')') { + else if (expr_s[1].value[i] == ')') { if (!op_close_acp_param) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " Unexpected operator - \')\': " + tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "Unexpected operator(" << tmp_param << "): " << expr_s[1].value); else if (tmp_param.empty()) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The name of the parameters of call component is empty: " + tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) << "The name of the parameters of call component is empty(" + << tmp_param << "): " << expr_s[1].value); else if (tmp_param == "NULL") goto next_op_mn; else if (find(tcmd_tmp.name_accept_params.begin(), tcmd_tmp.name_accept_params.end(), tmp_param) != tcmd_tmp.name_accept_params.end()) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The parameter was already specified in the internal parameters[" + tmp_param + - "]: " + tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "The parameter was already specified in the internal parameters(" << tmp_param + << "): " << expr_s[1].value); tcmd_tmp.name_accept_params.push_back(tmp_param); next_op_mn: - tmp_param.clear(); op_minus_and_next_arrow = 1; - op_close_acp_param = 0; + op_close_acp_param = 0; continue; } - else if (sub_expr[1].token_of_subexpr[0].token_val[i] == '-') { - if (!op_minus_and_next_arrow) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " Unexpected operator - \'-\': " + tmp_param + "\n", - "004"); - else if (i == sub_expr[1].token_of_subexpr[0].token_val.size() - 1 || - sub_expr[1].token_of_subexpr[0].token_val[i + 1] != '>') - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " Unexpected operator - \'-\': " + tmp_param + "\n", - "004"); - - colon = 1; + else if (expr_s[1].value[i] == '-') { + if (!op_minus_and_next_arrow || i == expr_s[1].value.size() - 1 || expr_s[1].value[i + 1] != '>') + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "Unexpected operator - \'-\'(" << tmp_param << "): " << expr_s[1].value); + + colon = 1; op_minus_and_next_arrow = 0; ++i; continue; } - else if (sub_expr[1].token_of_subexpr[0].token_val[i] == ':') { + else if (expr_s[1].value[i] == ':') { if (op_quote || op_target_hand_field) goto curr_sym; if (!colon) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " Unexpected operator - \':\': " + tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "Unexpected operator - \':\'(" << tmp_param << "): " << expr_s[1].value); else if (tmp_param.empty()) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The name of the returned value of call component is empty: " + tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) << "The name of the returned value of call component is empty(" + << tmp_param << "): " << expr_s[1].value); beg_param = 1; - colon = 0; + colon = 0; tcmd_tmp.returnable = tmp_param; tmp_param.clear(); @@ -821,53 +725,49 @@ void sl_func::create_templates(const std::vector &sub_ continue; } else if (beg_param) { - if (isalpha(sub_expr[1].token_of_subexpr[0].token_val[i])) { + if (isalpha(expr_s[1].value[i])) { beg_param = 0; - op_comma = 1; + op_comma = 1; is_name_features_bs = 1; goto curr_sym; } - else if (sub_expr[1].token_of_subexpr[0].token_val[i] != '<') - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The enumeration of parameters is expected: " + tmp_param + "\n", - "004"); + else if (expr_s[1].value[i] != '<') + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "The enumeration of parameters is expected(" << tmp_param << "): " << expr_s[1].value); beg_param = 0; end_param = 1; continue; } - else if (end_param && sub_expr[1].token_of_subexpr[0].token_val[i] == '>') { + else if (end_param && expr_s[1].value[i] == '>') { if ((was_close_used_internal_param || was_close_quote || was_close_op_target_hand) && tmp_param == "NULL") { was_close_used_internal_param = 0; goto next_arg; } if (used_internal_param || op_quote || op_target_hand_field) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The construction of using internal arguments, just string and handle to field of target " - "must comply with this structure - {OPEN_OPERATOR}SOMETHING{CLOSE_OPERATOR}: " + - tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "The construction of using internal arguments, just string and handle to field" + " of target must comply with this structure - {OPEN_OPERATOR}SOMETHING{CLOSE_OPERATOR}(" + << tmp_param << "): " << expr_s[1].value); else if ((!was_close_used_internal_param && !was_close_quote && !was_close_op_target_hand) && - (curr_scope.what_type(tmp_param) != 2 || - curr_scope.what_type(curr_scope.get_var_value(tmp_param)) != 2)) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " Template argument does not exist externally[" + tmp_param + "]" + "\n", - "004"); + (current_scope.what_type(tmp_param) != 2 || + current_scope.what_type(current_scope.get_var_value(tmp_param)) != 2)) + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "Template argument does not exist externally(" << tmp_param << "): " << expr_s[1].value); else if (was_close_used_internal_param && find(tcmd_tmp.name_accept_params.begin(), tcmd_tmp.name_accept_params.end(), tmp_param) == tcmd_tmp.name_accept_params.end()) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " Template argument does not exist internally[" + tmp_param + "]" + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "Template argument does not exist internally(" << tmp_param << "): " << expr_s[1].value); else if (was_close_quote) { - arg_tmp.arg_t = var::struct_sb::template_command::arg::type::string; + arg_tmp.arg_t = var::struct_sb::template_command::arg::type::string; was_close_quote = 0; } else if (was_close_op_target_hand) { @@ -880,17 +780,16 @@ void sl_func::create_templates(const std::vector &sub_ name_field_target.end()) goto proc_hand_target_field; } - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - "Field does not exist in target structure[" + tmp_param + "]" + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "Field does not exist in target structure(" << tmp_param << "): " << expr_s[1].value); } proc_hand_target_field: - arg_tmp.arg_t = var::struct_sb::template_command::arg::type::trgfield; + arg_tmp.arg_t = var::struct_sb::template_command::arg::type::trgfield; was_close_op_target_hand = 0; } else if (was_close_used_internal_param) { - arg_tmp.arg_t = var::struct_sb::template_command::arg::type::internal; + arg_tmp.arg_t = var::struct_sb::template_command::arg::type::internal; was_close_used_internal_param = 0; } else @@ -906,157 +805,141 @@ void sl_func::create_templates(const std::vector &sub_ tmp_param.clear(); end_param = 0; - op_comma = 1; + op_comma = 1; continue; } - else if (end_param && sub_expr[1].token_of_subexpr[0].token_val[i] == '\'') { + else if (end_param && expr_s[1].value[i] == '\'') { if ((!tmp_param.empty() || !end_param) && !op_quote) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The symbol - \' must be after the beginning of the argument: " + tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) << "The symbol - \' must be after the beginning of the argument(" + << tmp_param << "): " << expr_s[1].value); else if (!end_param && op_quote) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The symbol - \' must be at end of the argument: " + tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "The symbol - \' must be at end of the argument(" << tmp_param << "): " << expr_s[1].value); if (!op_quote) op_quote = 1; else { - op_quote = 0; + op_quote = 0; was_close_quote = 1; } continue; } - else if (end_param && sub_expr[1].token_of_subexpr[0].token_val[i] == '[') { + else if (end_param && expr_s[1].value[i] == '[') { if (!tmp_param.empty() || !end_param || op_target_hand_field) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The symbol - \'[\' must be after the beginning of the argument: " + tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "The symbol - \'[\' must be after the beginning of the argument(" << tmp_param + << "): " << expr_s[1].value); op_target_hand_field = 1; continue; } - else if (end_param && sub_expr[1].token_of_subexpr[0].token_val[i] == ']') { + else if (end_param && expr_s[1].value[i] == ']') { if (!end_param) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The symbol - \']\' must be at end of the argument: " + tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) << "The symbol - \']\' must be at end of the argument(" + << tmp_param << "): " << expr_s[1].value); - op_target_hand_field = 0; + op_target_hand_field = 0; was_close_op_target_hand = 1; continue; } - else if (end_param && sub_expr[1].token_of_subexpr[0].token_val[i] == '{') { + else if (end_param && expr_s[1].value[i] == '{') { if (!tmp_param.empty() || !end_param) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The symbol - \'}\' must be after the beginning of the argument: " + tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "The symbol - \'}\' must be after the beginning of the argument(" << tmp_param + << "): " << expr_s[1].value); used_internal_param = 1; continue; } - else if (end_param && sub_expr[1].token_of_subexpr[0].token_val[i] == '}') { + else if (end_param && expr_s[1].value[i] == '}') { if (!end_param) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The symbol - \'}\' must be at the end of the argument: " + tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) << "The symbol - \'}\' must be at the end of the argument(" + << tmp_param << "): " << expr_s[1].value); - used_internal_param = 0; + used_internal_param = 0; was_close_used_internal_param = 1; continue; } - else if (op_close_acp_param && sub_expr[1].token_of_subexpr[0].token_val[i] == ',') { + else if (op_close_acp_param && expr_s[1].value[i] == ',') { if (tmp_param == "NULL") - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " If the parameter is zero, there should be no other parameters: " + tmp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "If the parameter is zero, there should be no other parameters(" << tmp_param + << "): " << expr_s[1].value); tcmd_tmp.name_accept_params.push_back(tmp_param); tmp_param.clear(); continue; } else if (op_comma) { - if (sub_expr[1].token_of_subexpr[0].token_val[i] != ',' && !is_name_features_bs) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " The operator is expected - \',\': " + tmp_param + "\n", - "004"); - else if (sub_expr[1].token_of_subexpr[0].token_val[i] == ',' && is_name_features_bs) { - arg_tmp.arg_t = var::struct_sb::template_command::arg::type::features; + if (expr_s[1].value[i] != ',' && !is_name_features_bs) + _log << bwtools::fatal + << (log_message(log_type::fatal) << "The operator is expected - \',\'" << expr_s[1].value); + else if (expr_s[1].value[i] == ',' && is_name_features_bs) { + arg_tmp.arg_t = var::struct_sb::template_command::arg::type::features; arg_tmp.str_arg = tmp_param; tcmd_tmp.args.push_back(arg_tmp); tmp_param.clear(); - beg_param = 1; + beg_param = 1; is_name_features_bs = 0; - op_comma = 0; + op_comma = 0; continue; } else if (is_name_features_bs) { - if (!isalpha(sub_expr[1].token_of_subexpr[0].token_val[i]) && - sub_expr[1].token_of_subexpr[0].token_val[i] != '_') - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + " The symbol - \'" + - sub_expr[1].token_of_subexpr[0].token_val[i] + "\' was not expected: " + tmp_param + "\n", - "004"); + if (!isalpha(expr_s[1].value[i]) && expr_s[1].value[i] != '_') + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "The symbol - \'" << expr_s[1].value[i] << "\' was not expected: " << expr_s[1].value); goto curr_sym; } beg_param = 1; - op_comma = 0; + op_comma = 0; continue; } curr_sym: if (op_minus_and_next_arrow) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " The operator is expected - \'->\': " + sub_expr[1].token_of_subexpr[0].token_val + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) << "The operator is expected - \'->\':" << expr_s[1].value); else if (was_sep) { if (beg_param) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " Pattern parameter start operator expected: " + tmp_param + "\n ", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "Pattern parameter start operator expected(" << tmp_param << "): " << expr_s[1].value); else if (end_param) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " Pattern parameter end operator expected: " + tmp_param + "\n ", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "Pattern parameter end operator expected(" << tmp_param << "): " << expr_s[1].value); else if (is_name_features_bs || op_comma) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[1].token_of_subexpr[0]) + - " Expected end of parameter(comma operator): " + tmp_param + "\n ", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) + << "Expected comma operator(" << tmp_param << "): " << expr_s[1].value); } - tmp_param += sub_expr[1].token_of_subexpr[0].token_val[i]; + tmp_param += expr_s[1].value[i]; } if (beg_param) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " Template argument expected: " + sub_expr[1].token_of_subexpr[0].token_val + "\n", - "004"); + _log << bwtools::fatal << (log_message(log_type::fatal) << "Template argument expected: " << expr_s[1].value); else if (is_name_features_bs) { - arg_tmp.arg_t = var::struct_sb::template_command::arg::type::features; + arg_tmp.arg_t = var::struct_sb::template_command::arg::type::features; arg_tmp.str_arg = tmp_param; tcmd_tmp.args.push_back(arg_tmp); } - const auto &vec_templates_cmd = curr_scope.get_vector_variables_t(); + const auto &vec_templates_cmd = current_scope.get_vector_variables_t(); for (const std::string &acp_param : tcmd_tmp.name_accept_params) { bool find = 0; @@ -1068,64 +951,58 @@ void sl_func::create_templates(const std::vector &sub_ } if (!find) - throw semantic_an::rt_semantic_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " there is no command template that returns such a value: " + acp_param + "\n", - "004"); + _log << bwtools::fatal + << (log_message(log_type::fatal) << "There is no command template that returns such a value(" + << acp_param << "): " << expr_s[1].value); } - curr_scope.create_var(sub_expr[0].token_of_subexpr[0].token_val, tcmd_tmp); + current_scope.create_var(expr_s[0].value, tcmd_tmp); } -void sl_func::create_call_component(const std::vector &sub_expr, var::scope &curr_scope) { +void sl_func::create_call_component(const expressions &expr_s, var::scope ¤t_scope) { var::struct_sb::call_component ccmp_tmp; - ccmp_tmp.name = sub_expr[0].token_of_subexpr[0].token_val; - ccmp_tmp.name_program = sub_expr[1].token_of_subexpr[0].token_val; - ccmp_tmp.pattern_ret_files = sub_expr[2].token_of_subexpr[0].token_val; + ccmp_tmp.name = expr_s[0].value; + ccmp_tmp.name_program = expr_s[1].value; + ccmp_tmp.pattern_ret_files = expr_s[2].value; - curr_scope.create_var(sub_expr[0].token_of_subexpr[0].token_val, ccmp_tmp); + current_scope.create_var(expr_s[0].value, ccmp_tmp); } -void sl_func::use_templates(const std::vector &sub_expr, var::scope &curr_scope) { - if (curr_scope.what_type(sub_expr[0].token_of_subexpr[0].token_val) != 5) - throw interpreter::realtime_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " Var id of struct(expected project): " + sub_expr[0].token_of_subexpr[0].token_val + "\n", - "003"); - var::struct_sb::project &prj_ref = - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); - for (u32t i = 1; i < sub_expr.size(); ++i) { - if (curr_scope.what_type(sub_expr[i].token_of_subexpr[0].token_val) != 7) - throw interpreter::realtime_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " This template does not exist: " + sub_expr[i].token_of_subexpr[0].token_val + "\n", - "003"); - prj_ref.vec_templates.push_back(sub_expr[i].token_of_subexpr[0].token_val); +void sl_func::use_templates(const expressions &expr_s, var::scope ¤t_scope) { + if (current_scope.what_type(expr_s[0].value) != 5) + _log << bwtools::fatal << (log_message(log_type::fatal) << "Expected var project: " << expr_s[0].value); + + var::struct_sb::project &prj_ref = current_scope.get_var_value(expr_s[0].value); + + for (u32t i = 1; i < expr_s.size(); ++i) { + if (current_scope.what_type(expr_s[i].value) != 7) + _log << bwtools::fatal + << (log_message(log_type::fatal) << "This template does not exist: " << expr_s[i].value); + + prj_ref.vec_templates.push_back(expr_s[i].value); } - if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) - if (curr_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_UTEMPLATES) == 4) { - curr_scope.get_var_value>(prj_ref.name_project + PRJ_VAR_NAME_UTEMPLATES) = + if (current_scope.what_type(DECL_VAR_STRUCT) == 1 && current_scope.get_var_value(DECL_VAR_STRUCT) > 0) + if (current_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_UTEMPLATES) == 4) { + current_scope.get_var_value>(prj_ref.name_project + PRJ_VAR_NAME_UTEMPLATES) = prj_ref.vec_templates; } else - curr_scope.create_var>(prj_ref.name_project + PRJ_VAR_NAME_UTEMPLATES, - prj_ref.vec_templates); + current_scope.create_var>(prj_ref.name_project + PRJ_VAR_NAME_UTEMPLATES, + prj_ref.vec_templates); } -void sl_func::use_it_template(const std::vector &sub_expr, var::scope &curr_scope) { - if (curr_scope.what_type(sub_expr[0].token_of_subexpr[0].token_val) != 5) - throw interpreter::realtime_excp( - parser::utility::build_pos_tokenb_str(sub_expr[0].token_of_subexpr[0]) + - " Var id of struct(expected project): " + sub_expr[0].token_of_subexpr[0].token_val + "\n", - "003"); - - var::struct_sb::project &prj_ref = - curr_scope.get_var_value(sub_expr[0].token_of_subexpr[0].token_val); - prj_ref.use_it_templates = std::stoi(sub_expr[1].token_of_subexpr[0].token_val); - if (curr_scope.what_type("DECL_CONFIG_VAR") == 1 && curr_scope.get_var_value(DECL_VAR_STRUCT) > 0) - if (curr_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_UITTEMPLATES) == 1) { - curr_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_UITTEMPLATES) = prj_ref.use_it_templates; +void sl_func::use_it_template(const expressions &expr_s, var::scope ¤t_scope) { + if (current_scope.what_type(expr_s[0].value) != 5) + _log << bwtools::fatal << (log_message(log_type::fatal) << "Expected var project: " << expr_s[0].value); + + var::struct_sb::project &prj_ref = current_scope.get_var_value(expr_s[0].value); + prj_ref.use_it_templates = std::stoi(expr_s[1].value); + + if (current_scope.what_type(DECL_VAR_STRUCT) == 1 && current_scope.get_var_value(DECL_VAR_STRUCT) > 0) + if (current_scope.what_type(prj_ref.name_project + PRJ_VAR_NAME_UITTEMPLATES) == 1) { + current_scope.get_var_value(prj_ref.name_project + PRJ_VAR_NAME_UITTEMPLATES) = + prj_ref.use_it_templates; } else - curr_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_UITTEMPLATES, prj_ref.use_it_templates); + current_scope.create_var(prj_ref.name_project + PRJ_VAR_NAME_UITTEMPLATES, prj_ref.use_it_templates); } diff --git a/src/bs/lang/static_linking_func.hpp b/src/bs/lang/static_linking_func.hpp index 530ffec..ff75725 100644 --- a/src/bs/lang/static_linking_func.hpp +++ b/src/bs/lang/static_linking_func.hpp @@ -1,7 +1,8 @@ #ifndef _STATIC_LINKING_FUNC__H #define _STATIC_LINKING_FUNC__H -#include "parser.hpp" +#include +#include // all static global functions of the build system // ---------------------------------------------- @@ -11,96 +12,94 @@ // add_param_template, use_tamplates, use_it_template namespace sl_func { -using func_decl = void (*)(const std::vector &sub_expr, var::scope &curr_scope); +extern "C++" +{ -// list of all static global functions that -// should be called in semantic analysis (second pass) -extern const std::vector name_static_func_sm; + // A function that creates or modifies (if it already exists) a variable. + // Cannot work with variables that are structural (project, target) + void set(const expressions &expr_s, var::scope ¤t_scope); -// A function that creates or modifies (if it already exists) a variable. -// Cannot work with variables that are structural (project, target) -extern void set(const std::vector &sub_expr, var::scope &curr_scope); + // A function that finds (or performs other actions) files, + // defining paths for them, to prevent problems with the subsequent build of targets. + // Functions: + // 1. PATH + // 2. FIND + // 3. COPY + void file(const expressions &expr_s, var::scope ¤t_scope); -// A function that finds (or performs other actions) files, -// defining paths for them, to prevent problems with the subsequent build of targets. -// Functions: -// 1. PATH -// 2. FIND -// 3. COPY -extern void file(const std::vector &sub_expr, var::scope &curr_scope); + // Creates a project with a specific language and source files + void project(const expressions &expr_s, var::scope ¤t_scope); -// Creates a project with a specific language and source files -extern void project(const std::vector &sub_expr, var::scope &curr_scope); + // Creates a target with a specific configuration (RELEASE/DEBUG) + // and a main project + void executable(const expressions &expr_s, var::scope ¤t_scope); -// Creates a target with a specific configuration (RELEASE/DEBUG) -// and a main project -extern void executable(const std::vector &sub_expr, var::scope &curr_scope); + // Adds the specified libraries to the list of dependencies of the target (library) + void link_lib(const expressions &expr_s, var::scope ¤t_scope); -// Adds the specified libraries to the list of dependencies of the target (library) -extern void link_lib(const std::vector &sub_expr, var::scope &curr_scope); + // Exports all created variables or structures (by creating another + // interpreter for the file) + // from a file in another project using the same build system + void exp_data(const expressions &expr_s, var::scope ¤t_scope); -// Exports all created variables or structures (by creating another -// interpreter for the file) -// from a file in another project using the same build system -extern void exp_data(const std::vector &sub_expr, var::scope &curr_scope); + // Executes the passed string in cmd + void cmd(const expressions &expr_s, var::scope ¤t_scope); -// Executes the passed string in cmd -extern void cmd(const std::vector &sub_expr, var::scope &curr_scope); + // Outputs the passed text to the console + void debug(const expressions &expr_s, var::scope ¤t_scope); -// Outputs the passed text to the console -extern void debug(const std::vector &sub_expr, var::scope &curr_scope); + // Outputs the passed info of struct(project, target) to the console + void debug_struct(const expressions &expr_s, var::scope ¤t_scope); -// Outputs the passed info of struct(project, target) to the console -extern void debug_struct(const std::vector &sub_expr, var::scope &curr_scope); + // Sets compiler flags for the passed project depending on the configuration + void flags_compiler(const expressions &expr_s, var::scope ¤t_scope); -// Sets compiler flags for the passed project depending on the configuration -extern void flags_compiler(const std::vector &sub_expr, var::scope &curr_scope); + // Sets linker flags for the passed project depending on the configuration + void flags_linker(const expressions &expr_s, var::scope ¤t_scope); -// Sets linker flags for the passed project depending on the configuration -extern void flags_linker(const std::vector &sub_expr, var::scope &curr_scope); + // Sets the path to the compiler in project which was passed + void path_compiler(const expressions &expr_s, var::scope ¤t_scope); -// Sets the path to the compiler in project which was passed -extern void path_compiler(const std::vector &sub_expr, var::scope &curr_scope); + // Sets the path to the linker in project which was passed + void path_linker(const expressions &expr_s, var::scope ¤t_scope); -// Sets the path to the linker in project which was passed -extern void path_linker(const std::vector &sub_expr, var::scope &curr_scope); + // Sets the standard of the C language in project which was passed + void standart_c(const expressions &expr_s, var::scope ¤t_scope); -// Sets the standard of the C language in project which was passed -extern void standart_c(const std::vector &sub_expr, var::scope &curr_scope); + // Sets the standard of the C++ language in project which was passed + void standart_cpp(const expressions &expr_s, var::scope ¤t_scope); -// Sets the standard of the C++ language in project which was passed -extern void standart_cpp(const std::vector &sub_expr, var::scope &curr_scope); + // Sets the language of the project that was passed + void lang(const expressions &expr_s, var::scope ¤t_scope); -// Sets the language of the project that was passed -extern void lang(const std::vector &sub_expr, var::scope &curr_scope); + // Sets the base generator for the target that was passed. + void generator(const expressions &expr_s, var::scope ¤t_scope); -// Sets the base generator for the target that was passed. -extern void generator(const std::vector &sub_expr, var::scope &curr_scope); + // Creates a parameter declaration for a command template (variable) + // that refers to another variable. Therefore, the parameter for the template + // command will depend on the passed variable + void add_param_template(const expressions &expr_s, var::scope ¤t_scope); -// Creates a parameter declaration for a command template (variable) -// that refers to another variable. Therefore, the parameter for the template -// command will depend on the passed variable -extern void add_param_template(const std::vector &sub_expr, var::scope &curr_scope); + // Creates a template that can be used to generate commands + // ---------- + // #### NAME_CALL_COMPONENT(ACP1, ...) -> return NAME_smt: ,,<{ACP1}>, <[FIELD_TARGET_OR_PROJECT]>, + // FEATURES_CURRENT_GENERATOR ... Available components: COMPILER C/C++, LINKER C/C++, ARCHIVER, INTERPRETER, + // [user]... NAME_ret is file or list of files + void create_templates(const expressions &expr_s, var::scope ¤t_scope); -// Creates a template that can be used to generate commands -// ---------- -// #### NAME_CALL_COMPONENT(ACP1, ...) -> return NAME_smt: ,,<{ACP1}>, <[FIELD_TARGET_OR_PROJECT]>, -// FEATURES_CURRENT_GENERATOR ... Available components: COMPILER C/C++, LINKER C/C++, ARCHIVER, INTERPRETER, [user]... -// NAME_ret is file or list of files -extern void create_templates(const std::vector &sub_expr, var::scope &curr_scope); + // Creates a component of call + // ---------- + // Creates a call component with the name of the program that will be called + // when using this component, and also determines the pattern of files in the output of the program + void create_call_component(const expressions &expr_s, var::scope ¤t_scope); -// Creates a component of call -// ---------- -// Creates a call component with the name of the program that will be called -// when using this component, and also determines the pattern of files in the output of the program -extern void create_call_component(const std::vector &sub_expr, var::scope &curr_scope); + // Adds the name of the template that will be used when generating commands + void use_templates(const expressions &expr_s, var::scope ¤t_scope); -// Adds the name of the template that will be used when generating commands -extern void use_templates(const std::vector &sub_expr, var::scope &curr_scope); - -// Sets the flag of the passed project, whether to use templates for generating commands -extern void use_it_template(const std::vector &sub_expr, var::scope &curr_scope); + // Sets the flag of the passed project, whether to use templates for generating commands + void use_it_template(const expressions &expr_s, var::scope ¤t_scope); +} } // namespace sl_func -#endif \ No newline at end of file +#endif diff --git a/src/bs/lang/static_struct.hpp b/src/bs/lang/static_struct.hpp index b627f59..900db11 100644 --- a/src/bs/lang/static_struct.hpp +++ b/src/bs/lang/static_struct.hpp @@ -1,14 +1,14 @@ #ifndef _STATIC_STRUCT__H #define _STATIC_STRUCT__H -#include "../../kernel/high_level/bwtype.h" -#include "../bwconf_var.hpp" - #include #include #include #include +#include +#include + // The name of a variable that, when set to 1, // will allow project functions and many target functions // to create configuration variables for quick access to their internals. @@ -87,7 +87,7 @@ enum class type_target { interpret }; enum class configuration { - RELEASE, + RELEASE = 0, DEBUG }; @@ -254,7 +254,7 @@ struct template_command { features }; - arg() = default; + arg() = default; arg(const arg &) = default; arg(std::string _arg, type _arg_t) : str_arg(_arg), arg_t(_arg_t) { } diff --git a/src/bs/lang/token.hpp b/src/bs/lang/token.hpp deleted file mode 100644 index c2ef43c..0000000 --- a/src/bs/lang/token.hpp +++ /dev/null @@ -1,97 +0,0 @@ -// -// BWEAS is distributed under the GNU General Public License 2.0 (GPL-2.0). -// you can view the license text at the link: -// -// ------------------------------------------ -// - -#ifndef TOKEN__H -#define TOKEN__H - -#include "../../kernel/high_level/bwtype.h" -#include - -#define STR_KEYWORD_IF "if" -#define STR_KEYWORD_ELSE "else" -#define STR_KEYWORD_ENDIF "endif" - -#define STR_KEYWORD_OP_EQUAL "EQUAL" -#define STR_KEYWORD_OP_AND "AND" -#define STR_KEYWORD_OP_OR "OR" -#define STR_KEYWORD_OP_NOT "NOT" -#define STR_KEYWORD_OP_TSTR "TO_STR" - -#define STR_KEYWORD_OP_CONST_TRUE "TRUE" -#define STR_KEYWORD_OP_CONST_FALSE "FALSE" -#define STR_KEYWORD_OP_CONST_RELEASE "RELEASE" -#define STR_KEYWORD_OP_CONST_DEBUG "DEBUG" - -#define IS_BIBARY_KW_OP(STR) (STR == STR_KEYWORD_OP_EQUAL || STR == STR_KEYWORD_OP_AND || STR == STR_KEYWORD_OP_OR) -#define IS_UNARY_KW_OP(STR) (STR == STR_KEYWORD_OP_TSTR || STR == STR_KEYWORD_OP_NOT) - -#define RET_INT_KW_OP(STR) \ - (STR == STR_KEYWORD_OP_EQUAL || STR == STR_KEYWORD_OP_AND || STR == STR_KEYWORD_OP_NOT || STR == STR_KEYWORD_OP_OR) -#define RET_STR_KW_OP(STR) (STR == STR_KEYWORD_OP_TSTR) - -namespace token_expr { - -// listing all possible token types -enum class token_type { - KEYWORD = 0, - - // 1,2,3...(UINT_MAX32 / 2) - LITERAL, - - // "text" - LITERALS, - - ID, - - COMMA, - OPEN_BR, - CLOSE_BR, - - // > < = + - // only the + operator is a string addition operator - // (arithmetic operations are prohibited at the operator level) - // ----------------------------------------------------------- - // Also, strings cannot be compared (for now) - OPERATOR, - - // Special operators as keywords - KW_OPERATOR, - SIZE_ENUM_TOKEN_TYPE -}; - -// struct of token -struct token { - token() = default; - explicit token(token_type tk_t, std::string tk_val, i32t pos_def_line = -1, i32t pos_beg_def_sym = -1) - : token_t(tk_t), token_val(tk_val), pos_defined_line(pos_def_line), pos_beg_defined_sym(pos_beg_def_sym) { - } - - token &operator=(const token &tk) { - token_t = tk.token_t; - token_val = tk.token_val; - - return *this; - } - - token_type token_t; - std::string token_val; - - // token position in the text (line number) - i32t pos_defined_line{0}; - - // token position in the line (symbol number) - i32t pos_beg_defined_sym{0}; -}; -static inline bool operator==(const token &tk1, const token &tk2) { - if (tk1.token_t == tk2.token_t && tk1.token_val == tk2.token_val && tk1.pos_defined_line == tk2.pos_defined_line && - tk1.pos_beg_defined_sym == tk2.pos_beg_defined_sym) - return 1; - return 0; -} -} // namespace token_expr - -#endif diff --git a/src/bs/lang/var.hpp b/src/bs/lang/var.hpp index 881c184..70abe3b 100644 --- a/src/bs/lang/var.hpp +++ b/src/bs/lang/var.hpp @@ -1,7 +1,7 @@ #ifndef _VAR__H #define _VAR__H -#include "../../kernel/high_level/bwtype.h" +#include #include #include @@ -13,7 +13,7 @@ template class datatype_var { datatype_var() = default; datatype_var(const datatype_var &) = default; - datatype_var(datatype_var &&) = default; + datatype_var(datatype_var &&) = default; datatype_var &operator=(const datatype_var &dt_var); @@ -118,4 +118,4 @@ template void datatype_var::clear() { } // namespace var -#endif \ No newline at end of file +#endif diff --git a/src/bs/tools/bwfile.hpp b/src/bs/tools/bwfile.hpp index 50b107e..1a6dbab 100644 --- a/src/bs/tools/bwfile.hpp +++ b/src/bs/tools/bwfile.hpp @@ -8,11 +8,12 @@ #ifndef BWFILE__H #define BWFILE__H -#include "../../kernel/high_level/bwtype.h" - +#include #include #include +#include + namespace bwfile { // Creates an array of file names based on the mask diff --git a/src/bs/tools/bwlua.hpp b/src/bs/tools/bwlua.hpp index 6b4a110..0e56a9c 100644 --- a/src/bs/tools/bwlua.hpp +++ b/src/bs/tools/bwlua.hpp @@ -65,11 +65,14 @@ namespace bwlua { // Special tools - Wrappers over the lua class, // for simple interaction with the lua stack and others. namespace tools { + +inline void get_symbol(lua_State *L, std::string_view name_symbol); template inline void push_stack(lua_State *L, T param); template inline T pop_stack(lua_State *L, int idx = -1); // Calls a function that is on the top of the stack template inline T call_function(lua_State *L, Types... param); +template inline T call_function(lua_State *L, int count_param); } // namespace tools // A wrapper class for luajit. @@ -91,7 +94,7 @@ class lua { close(); } - lua(const lua &) = delete; + lua(const lua &) = delete; lua &operator=(lua &&) = delete; public: @@ -113,8 +116,8 @@ class lua { ~symbol() = default; private: - symbol() = delete; - symbol(symbol &&) = delete; + symbol() = delete; + symbol(symbol &&) = delete; symbol &operator=(symbol &&) = delete; explicit symbol(type _symbol_t, std::string _name_sym, lua *_L) @@ -206,16 +209,16 @@ class lua { template using ref = const T &; - template using array = std::vector; - template using key_value = std::pair; + template using array = std::vector; + template using key_value = std::pair; template using fast_table = std::vector>; - template using table = std::map; + template using table = std::map; using cfunc = int (*)(lua_State *); using string_param = std::string_view; - using integer = ptrdiff_t; - using number = double; + using integer = ptrdiff_t; + using number = double; private: template struct is_map : std::false_type {}; @@ -235,6 +238,7 @@ class lua { template friend inline void tools::push_stack(lua_State *L, T param); template friend inline T tools::pop_stack(lua_State *L, int idx); template friend inline T tools::call_function(lua_State *L, Types... param); + template friend inline T call_function(lua_State *L, int count_param); public: template static std::map to_map(table _table) { @@ -315,6 +319,11 @@ class lua { LUA_EXCEPTION() } + bool get_global_symbol(std::string_view name_symbol) { + lua_getglobal(L, name_symbol.data()); + return !lua_isnoneornil(L, -1); + } + // Calls a function, provided that it exists and all parameters match. // The first parameter of the template is the return type of the function. The remaining parameters are the types of // function parameters accepted @@ -604,7 +613,26 @@ class lua { pre_init_stack(params, std::index_sequence_for{}); - if (!lua_isfunction(L, 1)) + if (!lua_isfunction(L, -count_params)) + throw std::runtime_error(LUA_FUNCTION_NFOUND); + + if constexpr (!std::is_same_v && !std::is_same_v) { + if (lua_pcall(L, count_params, 1, 0) != LUA_OK) + LUA_EXCEPTION() + } + else if (lua_pcall(L, count_params, 0, 0) != LUA_OK) + LUA_EXCEPTION() + + if constexpr (std::is_same_v || std::is_same_v) + return; + else + return get_valsymbol(); + } + + // call symbol(function) in top of stack + // Assumes that the user parameters are already on the stack + template T call_symbol(int count_params) { + if (!lua_isfunction(L, -count_params)) throw std::runtime_error(LUA_FUNCTION_NFOUND); if constexpr (!std::is_same_v && !std::is_same_v) { @@ -681,6 +709,12 @@ template inline T pop_stack(lua_State *L, int idx) { template inline T call_function(lua_State *L, Types... param) { return lua(L).template call_symbol(param...); } +template inline T call_function(lua_State *L, int count_params) { + return lua(L).template call_symbol(count_params); +} +inline void get_symbol(lua_State *L, std::string_view name_symbol) { + (void)lua(L).get_global_symbol(name_symbol); +} } // namespace tools } // namespace bwlua diff --git a/src/bs/tools/bwlz4.hpp b/src/bs/tools/bwlz4.hpp index 5e26bad..ad2216b 100644 --- a/src/bs/tools/bwlz4.hpp +++ b/src/bs/tools/bwlz4.hpp @@ -8,22 +8,23 @@ #ifndef BWLZ4__h #define BWLZ4__h -#include "../../mdef.hpp" +#include #include #include +#include #define MB *1048576 namespace bwlz4 { // Compresses data based on lz4. If unsuccessful, returns an empty string -static inline std::string compress_data(std::string data) { +static inline std::string compress_data(std::string_view data) { if (data.size() >= LZ4_MAX_INPUT_SIZE || data.size() == 0) return ""; char *comp_data = (char *)malloc(LZ4_compressBound(data.size())); i32t size_comp_data; - if ((size_comp_data = LZ4_compress_default(data.c_str(), comp_data, data.size(), LZ4_compressBound(data.size()))) <= + if ((size_comp_data = LZ4_compress_default(data.data(), comp_data, data.size(), LZ4_compressBound(data.size()))) <= 0) { free(comp_data); return ""; @@ -37,13 +38,12 @@ static inline std::string compress_data(std::string data) { // Decompresses data based on lz4. In case of failure, expected_size = 0 or >= LZ4_MAX_INPUT_SIZE, an empty string is // returned. -static inline std::string decompress_data(std::string compress_data, u32t expected_size = 2 MB) { +static inline std::string decompress_data(std::string_view compress_data, u32t expected_size = 2 MB) { if (compress_data.size() >= LZ4_MAX_INPUT_SIZE || compress_data.size() == 0) return ""; char *decomp_data = (char *)malloc(expected_size); i32t size_data; - if ((size_data = LZ4_decompress_safe(compress_data.c_str(), decomp_data, compress_data.size(), expected_size)) < - 0) { + if ((size_data = LZ4_decompress_safe(compress_data.data(), decomp_data, compress_data.size(), expected_size)) < 0) { free(decomp_data); return ""; } diff --git a/src/bs/tools/call_cmd.hpp b/src/bs/tools/call_cmd.hpp index c079ad6..0378305 100644 --- a/src/bs/tools/call_cmd.hpp +++ b/src/bs/tools/call_cmd.hpp @@ -8,15 +8,14 @@ #ifndef CALL_CMD__H #define CALL_CMD__H -#include "../../mdef.hpp" +#include #include #include -namespace tools { class call_cmd_manager { public: - call_cmd_manager() = default; + call_cmd_manager() = default; call_cmd_manager(const call_cmd_manager &) = default; ~call_cmd_manager() = default; @@ -45,6 +44,5 @@ class call_cmd_manager { std::vector before_build; std::vector after_build; }; -} // namespace tools #endif diff --git a/src/bweas.cpp b/src/bweas.cpp index b3d0853..d759369 100644 --- a/src/bweas.cpp +++ b/src/bweas.cpp @@ -8,16 +8,8 @@ #include "bs/bwbuild_sys.hpp" int main(int argv, char **args) { - try { - clock_t beg = clock(); - bweas::bwbuilder bw(argv, args); - bw.set_logging(); - bw.start(); - assist << std::to_string((double)(clock() - beg) / CLOCKS_PER_SEC); - } - catch (bwexception::bweas_exception &excp) { - assist.call_err(excp.get_assist_err(), excp.what()); - } + bweas::bwbuilder bw(argv, args); + bw.start(); return 0; } diff --git a/src/kernel/high_level/assistant.cpp b/src/kernel/high_level/assistant.cpp deleted file mode 100644 index b1f27ee..0000000 --- a/src/kernel/high_level/assistant.cpp +++ /dev/null @@ -1,307 +0,0 @@ -#include "assistant.hpp" - -#include -#include -#include -#include - -#if defined(_WIN32) -#include "hook_winapi.hpp" -#include -#elif defined(UNIX) -#include -#include -#include - -extern "C" int init_hook(); -#endif - -assistant assist; - -assistant::assistant() { - err_s.emplace_back("KNL000", "Unable to open file", 0); - err_s.emplace_back("KNL001", "Unable to close file", 1); - err_s.emplace_back("KNL002", "File opened for reading", 2); - err_s.emplace_back("KNL003", "File opened for writing", 3); -} -assistant::assistant(bool _output, bool _log) : output(_output), log(_log) { -} - -assistant::~assistant() { -#if defined(WIN) - for (const auto &it : hDLL_s) - FreeLibrary(it.second); -#elif defined(UNIX) - for (const auto &it : hDL_s) - dlclose(it.second); -#endif -} - -void assistant::set_file_log_name(std::string name_file) { - if (name_file.empty()) - return; - log_file_name = name_file; - log = 1; - if (files.begin() + get_iterator_file(log_file_name) == files.end()) - open_file(name_file, file::mode_file::open::w); -} -void assistant::switch_otp(bool val) { - output = val; -} -void assistant::add_err(std::string name_err, std::string desc) { - err_s.emplace_back(name_err, desc, err_s.size()); -} -void assistant::call_err(std::string name_err) { - current_system_info = 1; - const auto &it = - std::find_if(err_s.begin(), err_s.end(), [name_err](const err &_err) { return _err.name_e == name_err; }); - if (it == err_s.end()) { - this->operator<<("An error with the name \"" + name_err + "\" was not found"); - exit(EXIT_FAILURE); - } - - this->operator<<(std::string(it->name_e) + "(" + std::to_string(it->ind) + "): " + it->desc_e); - exit(EXIT_FAILURE); -} -void assistant::call_err(std::string name_err, std::string addit) { - current_system_info = 1; - const auto &it = - std::find_if(err_s.begin(), err_s.end(), [name_err](const err &_err) { return _err.name_e == name_err; }); - if (it == err_s.end()) { - this->operator<<("An error with the name \"" + name_err + "\" was not found"); - exit(EXIT_FAILURE); - } - -#if defined(WIN) - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4); -#endif - if (addit.empty()) - this->operator<<(it->name_e + "(" + std::to_string(it->ind) + "): " + it->desc_e); - else - this->operator<<(it->name_e + "(" + std::to_string(it->ind) + "): " + it->desc_e + "\nDetail: [" + addit + "]"); -#if defined(WIN) - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7); -#endif - exit(EXIT_FAILURE); -} - -assistant::file_it assistant::open_file(std::string name_file, file::mode_file::open mode) { - try { - file_it it = get_iterator_file(name_file); - if (exist_file(it) && !(files.begin() + it)->file_opened) { - files[it].open(mode); - return it; - } - files.emplace_back(std::filesystem::absolute(name_file), mode); - return files.size() - 1; - } - catch (std::exception &excp) { - call_err("KNL000", excp.what()); - } -} -void assistant::close_file(assistant::file_it file) { - if (!exist_file(file)) - call_err("KNL001"); - files.erase(files.begin() + file); -} -bool assistant::exist_file(file_it file) { - if ((files.begin() + file) == files.end() || !(files.begin() + file)->file_opened) - return 0; - return 1; -} -bool assistant::exist_file(std::string name_file) { - if (std::filesystem::exists(name_file)) - return 1; - return 0; -} -assistant::file_it assistant::get_iterator_file(std::string name_file) { - return std::distance(files.begin(), - std::find_if(files.begin(), files.end(), [name_file](const assistant::file &file) { - return file.path_to == std::filesystem::absolute(name_file); - })); -} - -assistant::file &assistant::get_ref_file(file_it file) { - return *(files.begin() + file); -} - -std::string assistant::read_file(file &file, file::mode_file::input mode) { - CHECK_OPEN_FR() - - std::string data_file; - if (mode == file::mode_file::input::read_binary) { - u32t size_file; - file.stream.seekg(0, std::ios::end); - size_file = file.stream.tellg(); - file.stream.seekg(0, std::ios::beg); - data_file.resize(size_file); - file.stream.read(data_file.data(), size_file); - } - else { - std::string tmp; - while (std::getline(file.stream, tmp)) - data_file += tmp + "\n"; - } - - return data_file; -} -void assistant::write_file(file &file, std::string buf, file::mode_file::output mode) { - CHECK_OPEN_FW() - if (mode == file::mode_file::output::write_binary) - file.stream.write(buf.data(), buf.size()); - else - file.stream << buf; -} - -std::string assistant::get_time() { - auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); - tm *time_now = localtime(&time); - return std::to_string(time_now->tm_mon) + "." + std::to_string(time_now->tm_mday) + " " + - std::to_string(time_now->tm_hour) + ":" + std::to_string(time_now->tm_min); -} - -void assistant::next_output_unsuccess() { -#if defined(WIN) - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED); -#elif defined(UNIX) - printf("\033[31m"); -#endif -} -void assistant::next_output_important() { - current_system_info = 1; - -#if defined(WIN) - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); -#elif defined(UNIX) - printf("\033[33m"); -#endif -} -void assistant::next_output_success() { -#if defined(WIN) - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN); -#elif defined(UNIX) - printf("\033[32m"); -#endif -} -std::string assistant::get_path_program() { -#if defined(WIN) - char buffer[MAX_PATH]; - GetModuleFileNameA(NULL, buffer, MAX_PATH); -#elif defined(UNIX) - char buffer[PATH_MAX]; - ssize_t count = readlink("/proc/self/exe", buffer, PATH_MAX); -#endif - std::string str(buffer); - str.erase(str.find_last_of("/\\"), str.size()); - return str; -} -#if defined(WIN) -DWORD -assistant::get_error_win32() { - return GetLastError(); -} -HMODULE -assistant::load_dll(std::string name_file) { - HMODULE hDLL = LoadLibraryExA(name_file.c_str(), NULL, NULL); - if (!hDLL) - return NULL; - hDLL_s[name_file] = hDLL; - return hDLL; -} -void assistant::dump_dll(std::string dll_name) { - if (hDLL_s.find(dll_name) == hDLL_s.end()) - return; - FreeLibrary(hDLL_s[dll_name]); - hDLL_s.erase(dll_name); -} -void assistant::safe_call_dll_func_begin() { - _winapi_call_hook(); -} -void assistant::check_safe_call_dll_func() { - if (_winapi_call_knw_was_hook()) { - printf("\n"); - if (log) - write_file(*(files.begin() + get_iterator_file(log_file_name)), HOOK_TEXT_DETECTED, - file::mode_file::output::write_default); - exit(1); - } -} -void assistant::safe_call_dll_func_end() { - _winapi_call_remove(); -} -void *assistant::get_ptr_func(std::string dll_name, std::string name_func) { - if (hDLL_s.find(dll_name) == hDLL_s.end()) - return nullptr; - return GetProcAddress(hDLL_s[dll_name], name_func.c_str()); -} -HMODULE -assistant::get_handle_module_dll(std::string dll_name) { - if (hDLL_s.find(dll_name) == hDLL_s.end()) - return 0; - return hDLL_s[dll_name]; -} -#elif defined(UNIX) - -std::string assistant::get_error_dl() { - return dlerror(); -} - -u32t assistant::load_dl(std::string dl_name) { - if (hDL_s.find(dl_name) != hDL_s.end()) - return 1; - void *dlmem_p = dlopen(dl_name.c_str(), RTLD_LAZY); - if (dlmem_p == nullptr) - return 1; - hDL_s[dl_name] = dlmem_p; - return 0; -} -u32t assistant::dump_dl(std::string dl_name) { - if (hDL_s.find(dl_name) == hDL_s.end()) - return 1; - dlclose(hDL_s[dl_name]); - return 0; -} - -void *assistant::get_ptr_func(std::string dl_name, std::string name_func) { - if (hDL_s.find(dl_name) == hDL_s.end()) - return nullptr; - void *ptr_sym = dlsym(hDL_s[dl_name], name_func.c_str()); - return ptr_sym; -} - -void assistant::check_safe_call_dl_func() { - void *ptr_sym = dlsym(RTLD_DEFAULT, SBW_LIB_HOOK_STAT_SYM); - if (ptr_sym == nullptr) - return; - if (*((int *)ptr_sym)) { - if (log) - write_file(*(files.begin() + get_iterator_file(log_file_name)), HOOK_DETECTED_STR, - file::mode_file::output::write_default); - exit(1); - } -} - -void *assistant::get_realsystem_func() { - if (!realsystem_func) - realsystem_func = dlsym(RTLD_NEXT, "system"); - - return realsystem_func; -} - -#endif -void assistant::operator<<(std::string text) { - if (output) - printf("%s\n", text.c_str()); - if (log && current_system_info) { - const auto &log_file = files.begin() + get_iterator_file(log_file_name); - if (log_file != files.end() && log_file->file_opened) - write_file(*log_file, text + "\n", file::mode_file::output::write_default); - - current_system_info = 0; - } -#if defined(WIN) - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15); -#elif defined(UNIX) - printf("\033[0m"); -#endif -} diff --git a/src/kernel/high_level/assistant.hpp b/src/kernel/high_level/assistant.hpp deleted file mode 100644 index 7407840..0000000 --- a/src/kernel/high_level/assistant.hpp +++ /dev/null @@ -1,244 +0,0 @@ -#ifndef _ASSITANT__H_ -#define _ASSITANT__H_ - -#include "bwmacros_platform.h" -#include "bwtype.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#define CHECK_OPEN_FR() \ - if (file.mode_open != file::mode_file::open::rb && file.mode_open != file::mode_file::open::r) \ - call_err("KNL003", file.path_to.string()); - -#define CHECK_OPEN_FW() \ - if (file.mode_open != file::mode_file::open::w && file.mode_open != file::mode_file::open::wa && \ - file.mode_open != file::mode_file::open::wb) \ - call_err("KNL002", file.path_to.string()); - -class assistant { - public: - // output to console = true, log = false - assistant(); - assistant(const assistant &) = delete; - assistant &&operator=(assistant &&) = delete; - - assistant(bool _output, bool _log); - - ~assistant(); - - public: - struct file { - struct mode_file { - private: - mode_file() = delete; - - public: - // mode of open - enum class open { - // open for read of binary - rb = 0, - // open for default reading - r, - // open for overwrite or create file with writing - w, - // open for writes to the end of the file - wa, - // open for overwrite or create file with writing of binary - wb, - // open for writes to the end of the file of binary - wba - }; - - // mode of reading - enum class input { - // read of binary - read_binary, - // default reading - read_default - }; - // mode of writing - enum class output { - // write of binary(all bytes) - write_binary, - - // default writing - write_default - }; - }; - - public: - file() = default; - file(const file &) = delete; - file &operator=(const file &) = delete; - file(file &&_file) noexcept { - if (_file.file_opened) - _file.stream.close(); - path_to = _file.path_to; - mode_open = _file.mode_open; - open(); - } - file(std::filesystem::path _path_to, mode_file::open _mode_open) : path_to(_path_to), mode_open(_mode_open) { - open(); - } - ~file() { - close(); - } - file &operator=(file &&_file) noexcept { - if (_file.file_opened) - _file.stream.close(); - path_to = _file.path_to; - mode_open = _file.mode_open; - open(); - - return *this; - } - - void open(mode_file::open _mode_open, std::filesystem::path _path_to = {}) { - path_to = _path_to; - mode_open = _mode_open; - open(); - } - - // Opens a file with the specified mode - void open() { - if (mode_open == mode_file::open::rb) - stream.open(path_to.string(), std::ios::in | std::ios::binary); - else if (mode_open == mode_file::open::r) - stream.open(path_to.string(), std::ios::in); - else if (mode_open == mode_file::open::w) - stream.open(path_to.string(), std::ios::out | std::ios::trunc); - else if (mode_open == mode_file::open::wb) - stream.open(path_to.string(), std::ios::out | std::ios::binary | std::ios::trunc); - else if (mode_open == mode_file::open::wba) - stream.open(path_to.string(), std::ios::out | std::ios::binary | std::ios::app); - else - stream.open(path_to.string(), std::ios::out | std::ios::app); - - if (!stream.is_open()) - throw std::runtime_error("[" + path_to.string() + "] Failed to open file!"); - - file_opened = 1; - } - - // Closes the file if the stream is open - void close() { - if (file_opened) { - stream.close(); - file_opened = 0; - } - } - - public: - std::fstream stream; - std::filesystem::path path_to; - mode_file::open mode_open; - bool file_opened{0}; - }; - - public: - using file_it = u32t; - - void set_file_log_name(std::string name_file); - - // if output = false, the function does nothing - // *turns console output on or off (subsequent output requests will be ignored) - void switch_otp(bool val); - - // create err{struct *err} - void add_err(std::string name_err, std::string desc); - // detects and handles the error - void call_err(std::string name_err); - void call_err(std::string name_err, std::string addit); - - file_it open_file(std::string name_file, file::mode_file::open mode = file::mode_file::open::r); - void close_file(file_it file); - - bool exist_file(file_it file); - bool exist_file(std::string name_file); - - file_it get_iterator_file(std::string name_file); - file &get_ref_file(file_it file); - - std::string read_file(file &file, file::mode_file::input mode = file::mode_file::input::read_default); - void write_file(file &file, std::string buf, file::mode_file::output mode = file::mode_file::output::write_default); - - std::string get_time(); - - void next_output_unsuccess(); - void next_output_important(); - void next_output_success(); - - std::string get_path_program(); -#if defined(WIN) - DWORD - get_error_win32(); - - HMODULE - load_dll(std::string dll_name); - void dump_dll(std::string dll_name); - - void safe_call_dll_func_begin(); - void check_safe_call_dll_func(); - void safe_call_dll_func_end(); - - HMODULE - get_handle_module_dll(std::string dll_name); - -#elif defined(UNIX) - -#define SBW_LIB_HOOK_STAT_SYM "HOOK_STATUS" -#define HOOK_DETECTED_STR \ - "WARNING!!!A system call was detected, most likely the dynamically loaded dll library is hostile." - - std::string get_error_dl(); - - u32t load_dl(std::string dl_name); - u32t dump_dl(std::string dl_name); - - void check_safe_call_dl_func(); - void *get_realsystem_func(); - -#endif - void *get_ptr_func(std::string dl_name, std::string name_func); - - // output to console(if output = true) and logging(if log = true) - void operator<<(std::string text); - - private: - struct err { - public: - err(); - err(std::string_view _name_e, std::string_view _desc_e, u32t _ind) - : name_e(_name_e), desc_e(_desc_e), ind(_ind) { - } - - public: - std::string name_e; - std::string desc_e; - u32t ind; - }; - - std::vector err_s; - std::vector files; - - std::string log_file_name; - -#if defined(WIN) - std::unordered_map hDLL_s; -#elif defined(UNIX) - std::unordered_map hDL_s; - void *realsystem_func; -#endif - - bool output{1}, log{0}; - bool current_system_info{0}; -}; - -#endif diff --git a/src/kernel/high_level/bwmacros_platform.h b/src/kernel/high_level/bwmacros_platform.h deleted file mode 100644 index 40e6f30..0000000 --- a/src/kernel/high_level/bwmacros_platform.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef BWMACROS__H_ -#define BWMACROS__H_ - -// macro set - -#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) -#define UNIX -#if defined(__linux__) -#define _linux -#elif defined(__APPLE__) && defined(__MACH__) -#define APPLE_OS -#endif -#else -#if defined(_WIN32) || defined(_WIN64) -#define WIN -#include -#endif -#endif - -#if defined(__LP64__) || defined(_M_IA64) || defined(_WIN64) -#define X64 -#else -#define X32 -#endif - -#endif \ No newline at end of file diff --git a/src/kernel/high_level/bwtype.h b/src/kernel/high_level/bwtype.h deleted file mode 100644 index c6a278f..0000000 --- a/src/kernel/high_level/bwtype.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef BWTYPE__H_ -#define BWTYPE__H_ - -#include -#include - -typedef ptrdiff_t i32t; -typedef size_t u32t; -typedef unsigned short u16t; -typedef unsigned char u8t; - -#endif \ No newline at end of file diff --git a/src/kernel/high_level/hook_linux_lib/CMakeLists.txt b/src/kernel/high_level/hook_linux_lib/CMakeLists.txt deleted file mode 100644 index 5c43ca3..0000000 --- a/src/kernel/high_level/hook_linux_lib/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -project(dl_fbwhook) - -add_library(bwhook_safe SHARED decl_func_fbwhook.c) \ No newline at end of file diff --git a/src/kernel/high_level/hook_linux_lib/decl_func_fbwhook.c b/src/kernel/high_level/hook_linux_lib/decl_func_fbwhook.c deleted file mode 100644 index fc487d4..0000000 --- a/src/kernel/high_level/hook_linux_lib/decl_func_fbwhook.c +++ /dev/null @@ -1,113 +0,0 @@ -#define _GNU_SOURCE - -#include -#include -#include -#include - -#define HOOK_DETECTED 0xDEC -#define HOOK_DETECTED_NULL NULL -#define HOOK_DETECTED_STR \ - "WARNING!!!A system call was detected, most likely the dynamically loaded dll library is hostile." - -#define BEG_RED_TEXT "\033[1;31m" -#define END_RED_TEXT "\033[0m\n" - -#define HOOK_DETECTED_INF(add_inf) \ - printf(BEG_RED_TEXT HOOK_DETECTED_STR END_RED_TEXT "Detail: " add_inf "\n"); \ - HOOK_STATUS = 1; - -typedef int socklen_t; - -int HOOK_STATUS; - -int system(const char *string) { - HOOK_DETECTED_INF("system() call") - return HOOK_DETECTED; -} - -int chmod(const char *filename, int mode) { - HOOK_DETECTED_INF("chmod() call") - return HOOK_DETECTED; -} -int fchmod(int fildes, mode_t mode) { - HOOK_DETECTED_INF("fchmod() call") - return HOOK_DETECTED; -} -int chown(const char *pathname, uid_t owner, gid_t group) { - HOOK_DETECTED_INF("chown() call") - return HOOK_DETECTED; -} -int fchown(int fd, uid_t owner, gid_t group) { - HOOK_DETECTED_INF("fchown() call") - return HOOK_DETECTED; -} -int lchown(const char *pathname, uid_t owner, gid_t group) { - HOOK_DETECTED_INF("lchown() call") - return HOOK_DETECTED; -} -void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) { - HOOK_DETECTED_INF("mmap() call") - return NULL; -} -int munmap(void *start, size_t length) { - HOOK_DETECTED_INF("munmap() call") - return HOOK_DETECTED; -} -int setuid(uid_t uid) { - HOOK_DETECTED_INF("setuid() call") - return HOOK_DETECTED; -} -int setgid(gid_t gid) { - HOOK_DETECTED_INF("setgid() call") - return HOOK_DETECTED; -} -int seteuid(uid_t euid) { - HOOK_DETECTED_INF("seteuid() call") - return HOOK_DETECTED; -} -int setegid(gid_t egid) { - HOOK_DETECTED_INF("setegid() call") - return HOOK_DETECTED; -} -int listen(int sockfd, int backlog) { - HOOK_DETECTED_INF("listen() call") - return HOOK_DETECTED; -} -int socket(int domain, int type, int protocol) { - HOOK_DETECTED_INF("socket() call") - return HOOK_DETECTED; -} -int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { - HOOK_DETECTED_INF("bind() call") - return HOOK_DETECTED; -} -int recv(int s, void *buf, size_t len, int flags) { - HOOK_DETECTED_INF("recv() call") - return HOOK_DETECTED; -} -int recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) { - HOOK_DETECTED_INF("recvfrom() call") - return HOOK_DETECTED; -} -int recvmsg(int s, struct msghdr *msg, int flags) { - HOOK_DETECTED_INF("recvmsg() call") - return HOOK_DETECTED; -} -ssize_t send(int s, const void *msg, size_t len, int flags) { - HOOK_DETECTED_INF("send() call") - return HOOK_DETECTED; -} -ssize_t sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen) { - HOOK_DETECTED_INF("sendto() call") - return HOOK_DETECTED; -} -ssize_t sendmsg(int s, const struct msghdr *msg, int flags) { - HOOK_DETECTED_INF("sendmsg() call") - return HOOK_DETECTED; -} - -void init_hook() { - HOOK_STATUS = 0; - return; -} diff --git a/src/kernel/high_level/hook_winapi.cpp b/src/kernel/high_level/hook_winapi.cpp deleted file mode 100644 index c9765eb..0000000 --- a/src/kernel/high_level/hook_winapi.cpp +++ /dev/null @@ -1,152 +0,0 @@ -#include "hook_winapi.hpp" -#include - -#include - -static BOOL HOOK_PROCCES{0}; -static BOOL WAS_HOOK{0}; - -// List for success hook - real function of WinAPI -// - CreateProcessW, CreateProcessA -// - CreateRemoteThread, -// - VirtualAlloc, VirtualAllocEx -// - WriteProcessMemory, ReadProcessMemory -// - RegOpenKeyExW, RegOpenKeyExA -// -// - system -// ----------------------------------------------- -BOOL(WINAPI *realCreateProcessW) -(_In_opt_ LPCWSTR lpApplicationName, _Inout_opt_ LPWSTR lpCommandLine, - _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, - _In_ BOOL bInheritHandles, _In_ DWORD dwCreationFlags, _In_opt_ LPVOID lpEnvironment, - _In_opt_ LPCWSTR lpCurrentDirectory, _In_ LPSTARTUPINFOW lpStartupInfo, - _Out_ LPPROCESS_INFORMATION lpProcessInformation) = CreateProcessW; -BOOL(WINAPI *realCreateProcessA) -(_In_opt_ LPCSTR lpApplicationName, _Inout_opt_ LPSTR lpCommandLine, _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, - _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, _In_ BOOL bInheritHandles, _In_ DWORD dwCreationFlags, - _In_opt_ LPVOID lpEnvironment, _In_opt_ LPCSTR lpCurrentDirectory, _In_ LPSTARTUPINFOA lpStartupInfo, - _Out_ LPPROCESS_INFORMATION lpProcessInformation) = CreateProcessA; -HANDLE(WINAPI *realCreateRemoteThread) -(_In_ HANDLE hProcess, _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, _In_ SIZE_T dwStackSize, - _In_ LPTHREAD_START_ROUTINE lpStartAddress, _In_opt_ LPVOID lpParameter, _In_ DWORD dwCreationFlags, - _Out_opt_ LPDWORD lpThreadId) = CreateRemoteThread; -LPVOID(WINAPI *realVirtualAlloc) -(_In_opt_ LPVOID lpAddress, _In_ SIZE_T dwSize, _In_ DWORD flAllocationType, _In_ DWORD flProtect) = VirtualAlloc; -LPVOID(WINAPI *realVirtualAllocEx) -(_In_ HANDLE hProcess, _In_opt_ LPVOID lpAddress, _In_ SIZE_T dwSize, _In_ DWORD flAllocationType, - _In_ DWORD flProtect) = VirtualAllocEx; -BOOL(WINAPI *realWriteProcessMemory) -(_In_ HANDLE hProcess, _In_ LPVOID lpBaseAddress, _In_reads_bytes_(nSize) LPCVOID lpBuffer, _In_ SIZE_T nSize, - _Out_opt_ SIZE_T *lpNumberOfBytesWritten) = WriteProcessMemory; -BOOL(WINAPI *realReadProcessMemory) -(_In_ HANDLE hProcess, _In_ LPCVOID lpBaseAddress, _Out_writes_bytes_to_(nSize, *lpNumberOfBytesRead) LPVOID lpBuffer, - _In_ SIZE_T nSize, _Out_opt_ SIZE_T *lpNumberOfBytesRead) = ReadProcessMemory; -LSTATUS(APIENTRY *realRegOpenKeyExW) -(_In_ HKEY hKey, _In_opt_ LPCWSTR lpSubKey, _In_opt_ DWORD ulOptions, _In_ REGSAM samDesired, - _Out_ PHKEY phkResult) = RegOpenKeyExW; -LSTATUS(APIENTRY *realRegOpenKeyExA) -(_In_ HKEY hKey, _In_opt_ LPCSTR lpSubKey, _In_opt_ DWORD ulOptions, _In_ REGSAM samDesired, - _Out_ PHKEY phkResult) = RegOpenKeyExA; - -int(__cdecl *realsystem)(_In_opt_z_ char const *_Command) = system; - -BOOL WINAPI bwhookCreateProcessW(_In_opt_ LPCWSTR lpApplicationName, _Inout_opt_ LPWSTR lpCommandLine, - _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, - _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, _In_ BOOL bInheritHandles, - _In_ DWORD dwCreationFlags, _In_opt_ LPVOID lpEnvironment, - _In_opt_ LPCWSTR lpCurrentDirectory, _In_ LPSTARTUPINFOW lpStartupInfo, - _Out_ LPPROCESS_INFORMATION lpProcessInformation) { - hook_handleExA("CreateProcessW call", 20) return DETECTED_HOOK_N; -} -BOOL WINAPI bwhookCreateProcessA(_In_opt_ LPCSTR lpApplicationName, _Inout_opt_ LPSTR lpCommandLine, - _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, - _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, _In_ BOOL bInheritHandles, - _In_ DWORD dwCreationFlags, _In_opt_ LPVOID lpEnvironment, - _In_opt_ LPCSTR lpCurrentDirectory, _In_ LPSTARTUPINFOA lpStartupInfo, - _Out_ LPPROCESS_INFORMATION lpProcessInformation) { - hook_handleExA("CreateProcessA call", 20) return DETECTED_HOOK_N; -} -HANDLE -WINAPI -bwhookCreateRemoteThread(_In_ HANDLE hProcess, _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, - _In_ SIZE_T dwStackSize, _In_ LPTHREAD_START_ROUTINE lpStartAddress, - _In_opt_ LPVOID lpParameter, _In_ DWORD dwCreationFlags, _Out_opt_ LPDWORD lpThreadId) { - hook_handleExA("CreateRemoteThread call", 24) return DETECTED_HOOK_H; -} -LPVOID -WINAPI -bwhookVirtualAlloc(_In_opt_ LPVOID lpAddress, _In_ SIZE_T dwSize, _In_ DWORD flAllocationType, _In_ DWORD flProtect) { - hook_handleExA("VirtualAlloc call", 18) return DETECTED_HOOK_H; -} -LPVOID -WINAPI -bwhookVirtualAllocEx(_In_ HANDLE hProcess, _In_opt_ LPVOID lpAddress, _In_ SIZE_T dwSize, _In_ DWORD flAllocationType, - _In_ DWORD flProtect) { - hook_handleExA("VirtualAllocEx call", 20) return DETECTED_HOOK_H; -} -BOOL WINAPI bwhookWriteProcessMemory(_In_ HANDLE hProcess, _In_ LPVOID lpBaseAddress, - _In_reads_bytes_(nSize) LPCVOID lpBuffer, _In_ SIZE_T nSize, - _Out_opt_ SIZE_T *lpNumberOfBytesWritten) { - hook_handleExA("WriteProcessMemory call", 24) return DETECTED_HOOK_N; -} -BOOL WINAPI bwhookReadProcessMemory(_In_ HANDLE hProcess, _In_ LPCVOID lpBaseAddress, - _Out_writes_bytes_to_(nSize, *lpNumberOfBytesRead) LPVOID lpBuffer, - _In_ SIZE_T nSize, _Out_opt_ SIZE_T *lpNumberOfBytesRead) { - hook_handleExA("ReadProcessMemory call", 23) return DETECTED_HOOK_N; -} -LSTATUS -APIENTRY -bwhookRegOpenKeyExW(_In_ HKEY hKey, _In_opt_ LPCWSTR lpSubKey, _In_opt_ DWORD ulOptions, _In_ REGSAM samDesired, - _Out_ PHKEY phkResult) { - hook_handleExA("RegOpenKeyExW call", 19) return DETECTED_HOOK_N; -} -LSTATUS -APIENTRY -bwhookRegOpenKeyExA(_In_ HKEY hKey, _In_opt_ LPCSTR lpSubKey, _In_opt_ DWORD ulOptions, _In_ REGSAM samDesired, - _Out_ PHKEY phkResult) { - hook_handleExA("RegOpenKeyExA call", 19) return DETECTED_HOOK_N; -} -int __cdecl bwhooksystem(_In_opt_z_ char const *_Command) { - hook_handleExA("System() call", 19) return DETECTED_HOOK_N; -} - -void _winapi_call_hook() { - if (HOOK_PROCCES) - return; - DetourTransactionBegin(); - DetourUpdateThread(GetCurrentThread()); - DetourAttach(&(PVOID &)realCreateProcessW, bwhookCreateProcessW); - DetourAttach(&(PVOID &)realCreateProcessA, bwhookCreateProcessA); - DetourAttach(&(PVOID &)realCreateRemoteThread, bwhookCreateRemoteThread); - DetourAttach(&(PVOID &)realVirtualAlloc, bwhookVirtualAlloc); - DetourAttach(&(PVOID &)realVirtualAllocEx, bwhookVirtualAllocEx); - DetourAttach(&(PVOID &)realWriteProcessMemory, bwhookWriteProcessMemory); - DetourAttach(&(PVOID &)realReadProcessMemory, bwhookReadProcessMemory); - DetourAttach(&(PVOID &)realRegOpenKeyExW, bwhookRegOpenKeyExW); - DetourAttach(&(PVOID &)realRegOpenKeyExA, bwhookRegOpenKeyExA); - DetourAttach(&(PVOID &)realsystem, bwhooksystem); - DetourTransactionCommit(); - HOOK_PROCCES = 1; -} -void _winapi_call_remove() { - if (!HOOK_PROCCES) - return; - DetourTransactionBegin(); - DetourUpdateThread(GetCurrentThread()); - DetourDetach(&(PVOID &)realCreateProcessW, bwhookCreateProcessW); - DetourDetach(&(PVOID &)realCreateProcessA, bwhookCreateProcessA); - DetourDetach(&(PVOID &)realCreateRemoteThread, bwhookCreateRemoteThread); - DetourDetach(&(PVOID &)realVirtualAlloc, bwhookVirtualAlloc); - DetourDetach(&(PVOID &)realVirtualAllocEx, bwhookVirtualAllocEx); - DetourDetach(&(PVOID &)realWriteProcessMemory, bwhookWriteProcessMemory); - DetourDetach(&(PVOID &)realReadProcessMemory, bwhookReadProcessMemory); - DetourDetach(&(PVOID &)realRegOpenKeyExW, bwhookRegOpenKeyExW); - DetourDetach(&(PVOID &)realRegOpenKeyExA, bwhookRegOpenKeyExA); - DetourDetach(&(PVOID &)realsystem, bwhooksystem); - DetourTransactionCommit(); - HOOK_PROCCES = 0; -} - -BOOL _winapi_call_knw_was_hook() { - return WAS_HOOK; -} \ No newline at end of file diff --git a/src/kernel/high_level/hook_winapi.hpp b/src/kernel/high_level/hook_winapi.hpp deleted file mode 100644 index 6388972..0000000 --- a/src/kernel/high_level/hook_winapi.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef HOOK_WINAPI__H -#define HOOK_WINAPI__H - -#include -#include -#include -#include - -#define DETECTED_HOOK_H NULL -#define DETECTED_HOOK_N 0x0001 - -#define HOOK_TEXT_DETECTED \ - "WARNING!!! A winapi call was detected, most likely the dynamically loaded dll library is hostile.\n" -#define HOOK_TEXT_WARNING HOOK_TEXT_DETECTED "INFO: " - -#define hook_handleExW(info, size_info) \ - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4); \ - WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), (HOOK_TEXT_WARNING), 149, NULL, NULL); \ - WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), info, size_info, NULL, NULL); \ - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7); \ - WAS_HOOK = 1; -#define hook_handleExA(info, size_info) \ - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4); \ - WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), (HOOK_TEXT_WARNING), 149, NULL, NULL); \ - WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), info, size_info, NULL, NULL); \ - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7); \ - WAS_HOOK = 1; - -extern "C" -{ - void _winapi_call_hook(); - void _winapi_call_remove(); - - BOOL _winapi_call_knw_was_hook(); -} - -#endif \ No newline at end of file diff --git a/src/mdef.hpp b/src/mdef.hpp deleted file mode 100644 index bc0d8b0..0000000 --- a/src/mdef.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _MDEF__H -#define _MDEF__H - -#include "kernel/high_level/assistant.hpp" - -extern assistant assist; - -#endif \ No newline at end of file diff --git a/vcpkg.json b/vcpkg.json index 8fa2500..05d4d02 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -2,10 +2,9 @@ "name": "bweas", "version-string": "0.1.0", "dependencies": [ - "detours", "luajit", "nlohmann-json", "lz4", "gtest" ] - } +} From 6b412c46face2f79177d542f1b11571e1b467592 Mon Sep 17 00:00:00 2001 From: svec1 Date: Sat, 24 May 2025 13:38:31 +0000 Subject: [PATCH 05/38] fixed lua bugs --- src/bs/bwbuild_sys.cpp | 10 +++---- src/bs/bwcache_api.hpp | 8 +++--- src/bs/bwcache_lua.cpp | 2 +- src/bs/bwgenerator_api.hpp | 13 ++++----- src/bs/bwgenerator_lua.cpp | 12 ++++---- src/bs/bwlogger.cpp | 2 +- src/bs/bwluatools.cpp | 20 ++++++------- src/bs/bwluatools.hpp | 4 +-- src/bs/bwpackage.cpp | 59 +++++++++++++++++--------------------- src/bs/tools/bwlua.hpp | 54 ++++++++++++++++++++-------------- test/bs/tools/bwlua.hpp | 20 ++++++------- test/mtest.cpp | 4 +-- 12 files changed, 104 insertions(+), 104 deletions(-) diff --git a/src/bs/bwbuild_sys.cpp b/src/bs/bwbuild_sys.cpp index 2affdaf..a5d68bd 100644 --- a/src/bs/bwbuild_sys.cpp +++ b/src/bs/bwbuild_sys.cpp @@ -109,8 +109,8 @@ void bwbuilder::handle_args(std::vector &args) { u32t size_pckg = create_package(path_json_cfg_package); - (_log << bwtools::message) << (log_message(log_type::msg) - << "[Bweas-Package] Created: " + std::to_string(size_pckg) + " bytes"); + (_log << bwtools::message) + << (log_message(log_type::msg) << "Created: " + std::to_string(size_pckg) + " bytes"); } else { (_log << bwtools::error) << (log_message(log_type::error) << "Unknown argument: " + args[i]); @@ -296,14 +296,14 @@ u32t bwbuilder::gen_cache_target() { return 0; } - (_log << bwtools::message) << (log_message(log_type::msg) << " - [BWEAS]: Generating a cache file..."); + (_log << bwtools::message) << (log_message(log_type::msg) << "Generating a cache file..."); file_it bweas_cache = bwtools::open_file(CACHE_FILE, mf::open::w); bwtools::write_file(bwtools::get_ref_file(bweas_cache), cache->create_cache(), mf::output::write_binary); bwtools::close_file(bweas_cache); - (_log << bwtools::success) << (log_message(log_type::msg) << " - [BWEAS]: Cache generation was successful!"); + (_log << bwtools::success) << (log_message(log_type::msg) << "Cache generation was successful!"); return 1; } @@ -321,7 +321,7 @@ void bwbuilder::deserl_cache() { } void bwbuilder::build_targets() { - (_log << bwtools::message) << (log_message(log_type::msg) << " - [BWEAS]: Building targets..."); + (_log << bwtools::message) << (log_message(log_type::msg) << "Building targets..."); context.global_external_args.push_back(std::pair("", "")); diff --git a/src/bs/bwcache_api.hpp b/src/bs/bwcache_api.hpp index 28c52a7..d218ae3 100644 --- a/src/bs/bwcache_api.hpp +++ b/src/bs/bwcache_api.hpp @@ -13,10 +13,10 @@ #define NAME_FUNCTION_GENERATE_CACHE_LUA "create_cache" #define DEFINITION_FUNCTION_GENERATE_CACHE_LUA \ - std::string, bwluatools::ref>>, \ - bwluatools::ref>>, \ - bwluatools::ref>>, \ - bwluatools::ref>> + std::string, bwluatools::array>, \ + bwluatools::array>, \ + bwluatools::array>, \ + bwluatools::array> #define NAME_FUNCTION_GET_DATA_CACHE_LUA "get_cache_data" #define DEFINITION_FUNCTION_GET_DATA_CACHE_LUA void, bwluatools::nil diff --git a/src/bs/bwcache_lua.cpp b/src/bs/bwcache_lua.cpp index 8a3b5c2..d631497 100644 --- a/src/bs/bwcache_lua.cpp +++ b/src/bs/bwcache_lua.cpp @@ -31,7 +31,7 @@ void lua_bwcache::delete_cache() { std::string lua_bwcache::create_cache() { std::vector> ltargets_o; std::vector> ltcmd_s; - std::vector> lccmp_s; + std::vector> lccmp_s; for (const auto <arget_o : context->out_targets) ltargets_o.push_back(bwluatools::conv_to_table(ltarget_o)); diff --git a/src/bs/bwgenerator_api.hpp b/src/bs/bwgenerator_api.hpp index e1fb393..64dae64 100644 --- a/src/bs/bwgenerator_api.hpp +++ b/src/bs/bwgenerator_api.hpp @@ -19,22 +19,19 @@ // the path of the working directory - "CURRENT_DIR") #define NAME_FUNCTION_GENERATE_COMMAND_LUA "generate" #define DEFINITION_FUNCTION_GENERATE_COMMAND_LUA \ - bwluatools::table, \ - bwluatools::ref>> + bwluatools::table, bwluatools::table> // Accepts a name file, directory work #define NAME_FUNCTION_BUILD_DEPENDS_LUA "build_graph_depends_file" #define DEFINITION_FUNCTION_BUILD_DEPENDS_LUA \ - bwluatools::array, std::string_view, std::string_view, std::string_view, \ - bwluatools::ref> + bwluatools::array, std::string_view, std::string_view, std::string_view, std::vector // Accepts a target, its templates, and a global list of file trees (It can also use the "CCMPS" global variable) #define NAME_FUNCTION_GET_INPUT_FILE_LUA "get_input_files" #define DEFINITION_FUNCTION_GET_INPUT_FILE_LUA \ - bwluatools::table>, \ - bwluatools::ref>, \ - bwluatools::ref>>, \ - bwluatools::ref>> + bwluatools::table>, bwluatools::table, \ + bwluatools::array>, \ + bwluatools::table> namespace bweas { diff --git a/src/bs/bwgenerator_lua.cpp b/src/bs/bwgenerator_lua.cpp index 5a6444e..be89dbd 100644 --- a/src/bs/bwgenerator_lua.cpp +++ b/src/bs/bwgenerator_lua.cpp @@ -48,15 +48,14 @@ std::unordered_set lua_generator::build_graph_depends_file(std::str return std::unordered_set{dependencies.begin(), dependencies.end()}; } catch (std::exception &what) { - (log << bwtools::fatal) << (log_message(log_type::fatal) << "Run-time error" << what.what()); + (log << bwtools::fatal) << (log_message(log_type::fatal) << "Run-time error: " << what.what()); } } void lua_generator::get_input_files(data_transfer &data_t) { - bwluatools::array> ccmps; + bwluatools::array> ccmps; for (const auto &call_component : data_t.context->call_components) - ccmps.emplace_back(bwluatools::array{call_component.name, call_component.name_program, - call_component.pattern_ret_files}); + ccmps.emplace_back(bwluatools::conv_to_table(call_component)); bwluatools::array> tcmd_s_vec; for (const auto &_template : data_t.context->templates) tcmd_s_vec.emplace_back(bwluatools::conv_to_table(_template)); @@ -68,12 +67,11 @@ void lua_generator::get_input_files(data_transfer &data_t) { bwluatools::conv_to_table(data_t.dfiles))); } catch (std::exception &what) { - (log << bwtools::fatal) << (log_message(log_type::fatal) << "Run-time error" << what.what()); + (log << bwtools::fatal) << (log_message(log_type::fatal) << "Run-time error: " << what.what()); } } gen_command lua_generator::generate_command(data_transfer &data_t) { - generator::tools::parse_basic_args(*data_t.context->current_target, data_t.context->templates, data_t.context->global_external_args); @@ -90,6 +88,6 @@ gen_command lua_generator::generate_command(data_transfer &data_t) { NAME_FUNCTION_GENERATE_COMMAND_LUA, bwlua::lua::to_table(data_t.ifiles))); } catch (std::exception &what) { - (log << bwtools::fatal) << (log_message(log_type::fatal) << "Run-time error" << what.what()); + (log << bwtools::fatal) << (log_message(log_type::fatal) << "Run-time error: " << what.what()); } } diff --git a/src/bs/bwlogger.cpp b/src/bs/bwlogger.cpp index fde7135..00e09d0 100644 --- a/src/bs/bwlogger.cpp +++ b/src/bs/bwlogger.cpp @@ -49,7 +49,7 @@ logger &logger::operator<<(std::function handle_func_call void logger::operator<<(const log_message &obj) { status = obj.log_t; bwtools::write_file(bwtools::get_ref_file(file_log), - std::string("[") + owner.data() + std::string("]: ") + obj.ss.str()); + std::string("[") + owner.data() + std::string("]: ") + obj.ss.str() + "\n"); if (handle_func) { handle_func(std::string("[") + owner.data() + std::string("]: ") + obj.ss.str()); diff --git a/src/bs/bwluatools.cpp b/src/bs/bwluatools.cpp index e1c9046..ff75e49 100644 --- a/src/bs/bwluatools.cpp +++ b/src/bs/bwluatools.cpp @@ -20,19 +20,18 @@ bwluatools::table bwluatools::conv_to_table(const var::st {PRJ_VAR_NAME_RFLAGS_L, prj.rflags_linker}, {PRJ_VAR_NAME_DFLAGS_C, prj.dflags_compiler}, {PRJ_VAR_NAME_DFLAGS_L, prj.dflags_linker}, - {PRJ_VAR_NAME_STD_C, prj.standart_c}, - {PRJ_VAR_NAME_STD_CPP, prj.standart_cpp}, + {PRJ_VAR_NAME_STD_C, (bwluatools::integer)prj.standart_c}, + {PRJ_VAR_NAME_STD_CPP, (bwluatools::integer)prj.standart_cpp}, {PRJ_VAR_NAME_UITTEMPLATES, (bwlua::lua::integer)prj.use_it_templates}, {PRJ_VAR_NAME_SRC_FILES, prj.src_files}, {PRJ_VAR_NAME_UTEMPLATES, prj.vec_templates}, - {PRJ_VAR_NAME_CUSTOM_EXT_FIELDS, prj.custom_ext_fields}}; + {PRJ_VAR_NAME_CUSTOM_EXT_FIELDS, bwlua::lua::to_table(prj.custom_ext_fields)}}; } bwluatools::array bwluatools::conv_to_table(const std::vector &args) { - array vec_args; + bwluatools::array vec_args; for (const auto &arg : args) - vec_args.emplace_back( - bwlua::lua::key_value{arg.str_arg, (bwlua::lua::integer)arg.arg_t}); + vec_args.emplace_back(bwluatools::array{arg.str_arg, (bwlua::lua::integer)arg.arg_t}); return vec_args; } @@ -44,10 +43,11 @@ bwluatools::table bwluatools::conv_to_table(const var::st {NAME_FIELD_TEMPLATE_COMMAND_RET, tmp_c.returnable}}; } -bwluatools::table bwluatools::conv_to_table(const var::struct_sb::call_component &ccmp) { - return bwluatools::table{{NAME_FIELD_CALL_COMPONENT_NAME, ccmp.name}, - {NAME_FIELD_CALL_COMPONENT_NAME_PROGRAM, ccmp.name_program}, - {NAME_FIELD_CALL_COMPONENT_PATTERN_FILES, ccmp.pattern_ret_files}}; +bwluatools::table bwluatools::conv_to_table(const var::struct_sb::call_component &ccmp) { + return bwluatools::table{ + {NAME_FIELD_CALL_COMPONENT_NAME, ccmp.name}, + {NAME_FIELD_CALL_COMPONENT_NAME_PROGRAM, ccmp.name_program}, + {NAME_FIELD_CALL_COMPONENT_PATTERN_FILES, ccmp.pattern_ret_files}}; } bwluatools::table bwluatools::conv_to_table(const var::struct_sb::target &trg_o) { diff --git a/src/bs/bwluatools.hpp b/src/bs/bwluatools.hpp index 2f078c3..3c786d0 100644 --- a/src/bs/bwluatools.hpp +++ b/src/bs/bwluatools.hpp @@ -38,10 +38,10 @@ class bweas::bwluatools { public: static table conv_to_table(const var::struct_sb::project &prj); - static array conv_to_table(const std::vector &args); + static bwluatools::array conv_to_table(const std::vector &args); static table conv_to_table(const var::struct_sb::template_command &tmp_c); - static table conv_to_table(const var::struct_sb::call_component &ccmp); + static table conv_to_table(const var::struct_sb::call_component &ccmp); static table conv_to_table(const var::struct_sb::target &trg_o); static table conv_to_table(const var::struct_sb::target_out &trg_o); diff --git a/src/bs/bwpackage.cpp b/src/bs/bwpackage.cpp index e28c33a..c2ef2a6 100644 --- a/src/bs/bwpackage.cpp +++ b/src/bs/bwpackage.cpp @@ -27,26 +27,22 @@ std::string bwpackage::create_data_package(data_bw_package _data) { std::string bwpackage::init(data_bw_package _data, bool is_create_pckg) { nlohmann::json config_json = nlohmann::json::parse(_data.json_config); if (!config_json.contains("package-name") || ((name_package = config_json["package-name"]) == "")) - (_log << bwtools::error) << (log_message(log_type::error) << "Bweas package name field is empty"); + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Bweas package name field is empty"); else if (!config_json.contains("bweas-version") || ((bw_version = var::struct_sb::version(config_json["bweas-version"])) == "0.0.0")) - (_log << bwtools::error) << (log_message(log_type::error) << "Build system version field is empty"); - else if (!config_json.contains("custom_fields_project") && !config_json["custom_fields_project"].is_structured()) - (_log << bwtools::error) - << (log_message(log_type::error) - << "Definition of custom fields for the project must be in the form of key-value (string and string)"); - - cfg_package.custom_ext_fields_project = config_json["custom_fields_project"]; + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Build system version field is empty"); + else if (config_json.contains("custom_fields_project") && config_json["custom_fields_project"].is_object()) + cfg_package.custom_ext_fields_project = config_json["custom_fields_project"]; if (config_json.contains("cache-gn")) { nlohmann::json metainf_ch = config_json["cache-gn"]; if (!metainf_ch.is_structured()) - (_log << bwtools::error) << (log_message(log_type::error) << "The Cache field must be a structure"); + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "The Cache field must be a structure"); else if (!metainf_ch.contains("name") || !metainf_ch["name"].is_string()) - (_log << bwtools::error) << (log_message(log_type::error) << "Cache metadata must include its name"); + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Cache metadata must include its name"); else if (!metainf_ch.contains("src-luafile-cache") || !metainf_ch["src-luafile-cache"].is_string()) - (_log << bwtools::error) << (log_message(log_type::error) + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Cache metadata must include the path to the lua source file"); cfg_package.cache.name_cache = metainf_ch["name"]; @@ -59,10 +55,11 @@ std::string bwpackage::init(data_bw_package _data, bool is_create_pckg) { else cfg_package.cache.src_lua_cache = _data.src_lua_cache; } + // reading lua script file if (config_json.contains("generators")) { if (!config_json["generators"].is_structured()) - (_log << bwtools::error) << (log_message(log_type::error) + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "The \"generators\" field must be of type json structure"); u32t i = 0; @@ -71,21 +68,19 @@ std::string bwpackage::init(data_bw_package _data, bool is_create_pckg) { nlohmann::json metainf_gn = generator.value(); if (!metainf_gn.is_object()) - (_log << bwtools::error) << (log_message(log_type::error) + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "The generator meta information unit must be a json object"); else if (!metainf_gn.contains("src-luafile-gen") || !metainf_gn["src-luafile-gen"].is_string()) - (_log << bwtools::error) - << (log_message(log_type::error) + (_log << bwtools::fatal) + << (log_message(log_type::fatal) << "Generator metadata must include the path to the lua (generator) source code file"); else if (!metainf_gn.contains("features-generator") || !metainf_gn["features-generator"].is_array()) - (_log << bwtools::error) << (log_message(log_type::error) + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Generator metadata should include a list of new generator features"); - else if (config_json.contains("use_custom_search_dependencies") && - !config_json["use_custom_search_dependencies"].is_boolean()) - (_log << bwtools::error) - << (log_message(log_type::error) - << "Definition of custom fields for the project must be in the form of key-value (string and " - "string)"); + else if (!metainf_gn.contains("use_custom_search_dependencies") || + !metainf_gn["use_custom_search_dependencies"].is_boolean()) + (_log << bwtools::fatal) << (log_message(log_type::fatal) + << "Field - uses custom dependency lookup, expected boolean type"); auto it_gnlua_script = bwtools::open_file((std::string)metainf_gn["src-luafile-gen"]); if (is_create_pckg) { cfg_package.generators.emplace_back(generator.key(), metainf_gn["features-generator"], @@ -104,16 +99,16 @@ std::string bwpackage::init(data_bw_package _data, bool is_create_pckg) { } if (config_json.contains("modules")) { if (!config_json["modules"].is_structured()) - (_log << bwtools::error) << (log_message(log_type::error) + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "The \"generators\" field must be of type json structure"); for (const auto &module : config_json["modules"].items()) { nlohmann::json metainf_md = module.value(); std::vector funcs; - if (!metainf_md.contains("lua source file") || !metainf_md["lua source file"].is_string()) - (_log << bwtools::error) << (log_message(log_type::error) + if (!metainf_md.contains("src-luafile-md") || !metainf_md["src-luafile-md"].is_string()) + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Module metadata must include the name of the lua source file"); else if (!metainf_md.contains("functions") || !metainf_md["functions"].is_object()) - (_log << bwtools::error) << (log_message(log_type::error) + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Module metadata must include the functions they provide for import"); for (const auto &func : metainf_md["functions"].items()) { @@ -123,8 +118,8 @@ std::string bwpackage::init(data_bw_package _data, bool is_create_pckg) { for (const auto &field : it_func.items()) { if (field.key() == "accepted") { if (!field.value().is_array()) - (_log << bwtools::error) - << (log_message(log_type::error) + (_log << bwtools::fatal) + << (log_message(log_type::fatal) << "The field for listing the types of function parameters must be an array"); for (u32t i = 0; i < field.value().size(); ++i) { if (field.value()[i].is_string()) @@ -137,7 +132,7 @@ std::string bwpackage::init(data_bw_package _data, bool is_create_pckg) { } funcs.push_back(def_func_tmp); } - cfg_package.modules.emplace_back(module.key(), metainf_md["lua source file"], funcs); + cfg_package.modules.emplace_back(module.key(), metainf_md["src-luafile-md"], funcs); } } @@ -149,11 +144,11 @@ std::string bwpackage::init(data_bw_package _data, bool is_create_pckg) { void bwpackage::load(std::string_view raw_data_package) { std::string data_pckg = bwlz4::decompress_data(raw_data_package, MAX_SIZE_BW_PACKAGE); if (data_pckg.size() == 0) - (_log << bwtools::error) << (log_message(log_type::error) << "Unsuccessful decompression of package bweas"); + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Unsuccessful decompression of package bweas"); if (data_pckg.find(BW_PACKAGE_PREFIX_BYTE) == data_pckg.npos && data_pckg.find(BW_PACKAGE_SEPARATE_JSON_BYTES) == data_pckg.npos) - (_log << bwtools::error) << (log_message(log_type::error) << "Incorrect bweas package structure" + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "Incorrect bweas package structure" << "[Package: " << data_pckg.size() << " bytes]"); std::string prefix_package = data_pckg; @@ -161,7 +156,7 @@ void bwpackage::load(std::string_view raw_data_package) { prefix_package.erase(BW_PACKAGE_VERSION_BWEAS_VERSION_LENGHT); if (var::struct_sb::version(prefix_package) < var::struct_sb::version(BW_PACKAGE_PREFIX_BYTE)) - (_log << bwtools::error) << (log_message(log_type::error) + (_log << bwtools::fatal) << (log_message(log_type::fatal) << "The package of this version is not supported by the build system" << "[Package: " << data_pckg.size() << " bytes] Ver pckg: " << prefix_package); data_pckg.erase(0, BW_PACKAGE_START_BYTES_LENGHT); diff --git a/src/bs/tools/bwlua.hpp b/src/bs/tools/bwlua.hpp index 0e56a9c..56c980e 100644 --- a/src/bs/tools/bwlua.hpp +++ b/src/bs/tools/bwlua.hpp @@ -257,8 +257,8 @@ class lua { public: std::string get_string_stack() { std::string str = "STACK(" + std::to_string(lua_gettop(L)) + "):\n"; - for (ptrdiff_t i = 0; i < lua_gettop(L); ++i) { - if (i < lua_gettop(L) - 1) + for (ptrdiff_t i = 1; i <= lua_gettop(L); ++i) { + if (i < lua_gettop(L)) str += "| " + std::to_string(lua_gettop(L) - i) + " "; else str += "V " + std::to_string(lua_gettop(L) - i) + " "; @@ -276,7 +276,7 @@ class lua { else str += "???"; - if (i < lua_gettop(L) - 1) + if (i < lua_gettop(L)) str += "\n"; } @@ -330,6 +330,7 @@ class lua { template T call_function(std::string name_func, Types... param) { if (!is_created()) return T{}; + lua_settop(L, 0); lua_getglobal(L, name_func.data()); try { return call_symbol(param...); @@ -387,15 +388,15 @@ class lua { inline bool is_function(std::string_view name_func) { if (!is_created()) return 0; - else { - lua_getglobal(L, name_func.data()); + lua_getglobal(L, name_func.data()); - if (!lua_isfunction(L, -1)) { - lua_pop(L, 1); - return 0; - } + if (!lua_isfunction(L, -1)) { lua_pop(L, 1); + return 0; } + + lua_pop(L, 1); + return 1; } @@ -403,12 +404,15 @@ class lua { inline bool is_var(std::string_view name_var) { if (!is_created()) return 0; - else { - lua_getglobal(L, name_var.data()); + lua_getglobal(L, name_var.data()); - if (lua_isnoneornil(L, -1)) - return 0; + if (lua_isnoneornil(L, -1) || lua_isfunction(L, -1)) { + lua_pop(L, 1); + return 0; } + + lua_pop(L, 1); + return 1; } @@ -421,6 +425,8 @@ class lua { lua_pushinteger(L, param); else if constexpr (std::is_same_v) lua_pushnumber(L, param); + else if constexpr (std::is_same_v) + lua_pushstring(L, param); else if constexpr (std::is_same_v || std::is_same_v) lua_pushstring(L, param.data()); else if constexpr (is_map::value) { @@ -446,13 +452,15 @@ class lua { } else if constexpr (std::is_same_v) { if (param.type() == typeid(integer)) - lua_pushinteger(L, std::any_cast(param)); + push_stack_param(std::any_cast(param)); else if (param.type() == typeid(number)) - lua_pushnumber(L, std::any_cast(param)); + push_stack_param(std::any_cast(param)); else if (param.type() == typeid(std::string)) - lua_pushstring(L, std::any_cast(param).c_str()); + push_stack_param(std::any_cast(param)); else if (param.type() == typeid(std::string_view)) - lua_pushstring(L, std::any_cast(param).data()); + push_stack_param(std::any_cast(param)); + else if (param.type() == typeid(const char *)) + push_stack_param(std::string_view(std::any_cast(param))); else if (param.type() == typeid(std::vector)) push_stack_param(std::any_cast>(param)); @@ -610,10 +618,12 @@ class lua { template T call_symbol(Types... param) { std::tuple params(param...); size_t count_params = std::tuple_size::value; + if (count_params == 1 && std::is_same_v>, nil>) + count_params = 0; + else + pre_init_stack(params, std::index_sequence_for{}); - pre_init_stack(params, std::index_sequence_for{}); - - if (!lua_isfunction(L, -count_params)) + if (!lua_isfunction(L, -count_params - 1)) throw std::runtime_error(LUA_FUNCTION_NFOUND); if constexpr (!std::is_same_v && !std::is_same_v) { @@ -624,7 +634,7 @@ class lua { LUA_EXCEPTION() if constexpr (std::is_same_v || std::is_same_v) - return; + lua_pop(L, 1); else return get_valsymbol(); } @@ -632,7 +642,7 @@ class lua { // call symbol(function) in top of stack // Assumes that the user parameters are already on the stack template T call_symbol(int count_params) { - if (!lua_isfunction(L, -count_params)) + if (!lua_isfunction(L, -count_params - 1)) throw std::runtime_error(LUA_FUNCTION_NFOUND); if constexpr (!std::is_same_v && !std::is_same_v) { diff --git a/test/bs/tools/bwlua.hpp b/test/bs/tools/bwlua.hpp index c1c9623..7524208 100644 --- a/test/bs/tools/bwlua.hpp +++ b/test/bs/tools/bwlua.hpp @@ -37,24 +37,25 @@ TEST(BWWRAP_LUA, NoThrowInitClassBwLua) { TEST(BWWRAP_LUA, NoThrowClassBwLuaVariablePerformance) { bwlua::lua ltest(TEST1_SOURCE_LUA); - bwlua::lua::fastTable test_var_vec{{"test", "HELLO WORLD!"}, - {"test2", (bwlua::lua::integer)2}}; + bwlua::lua::fast_table test_var_vec{{"test", std::string("HELLO WORLD!")}, + {"test2", (bwlua::lua::integer)2}}; bwlua::lua::array nums = {1, 2, 3, 4, 5}; std::string str_tmp; ASSERT_NO_THROW({ - ltest["test"] = test_var_vec; + ltest["test"] = test_var_vec; ltest["test2"] = nums; }); ASSERT_EQ(std::any_cast( - ltest["test"].getval>()[0].second), + ltest["test"].getval>()[0].second), 2); ASSERT_EQ(ltest["test2"].getval>()[2], 3); } TEST(BWWRAP_LUA, NoThrowClassBwLuaCallFunction) { bwlua::lua ltest(TEST1_SOURCE_LUA); - bwlua::lua::fastTable test_var_vec{{"test", "HELLO WORLD!"}, {"test2", "HELLO WORLD!"}}; + bwlua::lua::fast_table test_var_vec{{"test", "HELLO WORLD!"}, + {"test2", "HELLO WORLD!"}}; bwlua::lua::array nums = {1, 2, 3, 4, 5}; std::string str_tmp; int num_tmp; @@ -68,7 +69,7 @@ TEST(BWWRAP_LUA, NoThrowClassBwLuaCallFunction) { // test_func2() ASSERT_NO_THROW({ num_tmp = ltest.call_function("test_func2", (bwlua::lua::integer)4, "Hello, ", - (bwlua::lua::integer)5, "World!"); + (bwlua::lua::integer)5, "World!"); }); ASSERT_EQ(num_tmp, 9); @@ -87,12 +88,11 @@ TEST(BWWRAP_LUA, NoThrowClassBwLuaVariableAStackNBad) { int num_tmp; for (bwlua::lua::integer i = 0; i < 1000; ++i) { - ASSERT_NO_THROW({ - num_tmp = ltest.call_function("test_func2", i, "Hello, ", i * 10, "World!"); - }); + ASSERT_NO_THROW( + { num_tmp = ltest.call_function("test_func2", i, "Hello, ", i * 10, "World!"); }); ASSERT_EQ(num_tmp, i + i * 10); ASSERT_EQ(ltest.get_var("str_g"), "Hello, World!"); } } -#endif \ No newline at end of file +#endif diff --git a/test/mtest.cpp b/test/mtest.cpp index e1cc4d8..5ef2c7e 100644 --- a/test/mtest.cpp +++ b/test/mtest.cpp @@ -1,9 +1,9 @@ #include "bs/tools/bwlua.hpp" #include "bs/tools/bwlz4.hpp" -#include "bs/lang/lang_tests.hpp" +// #include "bs/lang/lang_tests.hpp" int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); -} \ No newline at end of file +} From c781ae2c744e85bf3a5729ef8f5aa557b7fab90a Mon Sep 17 00:00:00 2001 From: svec1 Date: Mon, 2 Jun 2025 16:20:16 +0000 Subject: [PATCH 06/38] added integral generator of commands --- src/bs/bw_defs.hpp | 5 +- src/bs/bwbuild_sys.cpp | 26 ++-- src/bs/bwcache_fast.cpp | 7 +- src/bs/bwconf_var.hpp | 2 + src/bs/bwdepends_files.cpp | 31 ++++- src/bs/bwdepends_files.hpp | 15 ++- src/bs/bwdepends_generator.hpp | 6 +- src/bs/bwdepends_integral.cpp | 67 ++++++++++ src/bs/bwdepends_integral.hpp | 11 +- src/bs/bwgenerator_api.hpp | 19 ++- src/bs/bwgenerator_integral.cpp | 216 ++++++++++++++++++++++++++++---- src/bs/bwgenerator_integral.hpp | 16 +-- src/bs/bwgenerator_lua.cpp | 4 +- src/bs/bwgntools.cpp | 21 +++- src/bs/bwgntools.hpp | 30 +++-- src/bs/bwluatools.cpp | 2 +- src/bs/bwluatools.hpp | 3 + src/bs/bwtools.hpp | 3 + src/bs/lang/static_struct.hpp | 4 +- src/bs/tools/bwexception.hpp | 39 ------ src/bs/tools/bwfile.hpp | 51 +++++++- src/bs/tools/bwlua.hpp | 3 - 22 files changed, 435 insertions(+), 146 deletions(-) create mode 100644 src/bs/bwdepends_integral.cpp delete mode 100644 src/bs/tools/bwexception.hpp diff --git a/src/bs/bw_defs.hpp b/src/bs/bw_defs.hpp index 464c4f4..646ae9c 100644 --- a/src/bs/bw_defs.hpp +++ b/src/bs/bw_defs.hpp @@ -16,17 +16,16 @@ #include #include -#include #include #include #include -#define BWEAS_VERSION_STR "0.1.0" +#define BWEAS_VERSION_STR "0.1.1" #define BWEAS_VERSION_MAJOR "0" #define BWEAS_VERSION_MINOR "1" -#define BWEAS_VERSION_PATCH "0" +#define BWEAS_VERSION_PATCH "1" #define BWEAS_INFO "bweas version " BWEAS_VERSION_STR "\nrep on github - https://github.com/svec1/bweas" diff --git a/src/bs/bwbuild_sys.cpp b/src/bs/bwbuild_sys.cpp index a5d68bd..cb619ac 100644 --- a/src/bs/bwbuild_sys.cpp +++ b/src/bs/bwbuild_sys.cpp @@ -216,11 +216,11 @@ void bwbuilder::init() { } } - generators.emplace("bwgenerator", std::shared_ptr( - generator_api::base_generator::create_generator_int( - generator::bwgenerator, generator::bwbuild_graph_depends_file, - generator::bwget_input_files), - [](generator_api::base_generator *ptr) { ptr->_delete(); })); + generators.emplace("bwgenerator", + std::shared_ptr( + generator_api::base_generator::create_generator_int( + nullptr, integral_generator::get_input_files, integral_generator::generate), + [](generator_api::base_generator *ptr) { ptr->_delete(); })); for (const auto &package : loaded_packages) for (const auto &generator : package.cfg_package.generators) { @@ -359,37 +359,41 @@ void bwbuilder::build_targets() { else depends_files = std::make_unique(target.prj.language, dir_target); + depends_files->set_include_paths(target.prj.include_paths); + for (const auto &name_file : target.prj.src_files) { std::string name_depends_file = name_file + DEPENDS_FILE_POSTFIX; if (bwtools::exist_file(name_depends_file)) depends_files->build_graph_depends_file_string( name_file, bwtools::read_file(bwtools::get_ref_file(bwtools::open_file(name_depends_file)))); - else + else { + depends_files->build_graphs_depends_file_v(name_file); bwtools::write_file(bwtools::get_ref_file(bwtools::open_file(name_depends_file, mf::open::w)), depends_files->get_string_depends_file(name_file)); + } } - depends_files->build_graphs_depends_files(target.prj.src_files, target.prj.include_paths); + depends_files->build_graphs_depends_files(target.prj.src_files); data_t.dfiles = depends_files->get_graphs_depends_files(); (_log << bwtools::message) << (log_message(log_type::msg) << "Build {" << target.name_target << "}"); current_generator->get_input_files(data_t); + auto cmd_s = current_generator->generate_command(data_t); for (const auto &cmd : cmd_s) { + build_state += 1.f / (double)cmd_s.size() * 100; (_log << bwtools::message) << (log_message(log_type::msg) - << "[" << std::to_string(build_state).erase(std::to_string((u32t)build_state).size() + 3, 4) - << "%]Compile - " << cmd.first); + << "[" << std::to_string(build_state).erase(std::to_string((u32t)build_state).size() + 2, 5) + << "%] " << cmd.first); if (system(cmd.second.c_str())) (_log << bwtools::warning) << (log_message(log_type::warning) << "Failed build. Command execution error: \n" << cmd.second); - - build_state += 1.f / (double)cmd_s.size() * 100; } } } diff --git a/src/bs/bwcache_fast.cpp b/src/bs/bwcache_fast.cpp index 5b324a7..bf0a5f8 100644 --- a/src/bs/bwcache_fast.cpp +++ b/src/bs/bwcache_fast.cpp @@ -236,8 +236,13 @@ void fast_bwcache::extract_cache_data(std::string &&cache_str) { } } else { - if (count_word == 1) + if (count_word == 1) { + trg_tmp.prj.include_paths.clear(); + trg_tmp.prj.vec_templates.clear(); + trg_tmp.prj.custom_ext_fields.clear(); + trg_tmp.target_vec_libs.clear(); size_src_files = std::stoi(str_tmp); + } else if (count_word == 2) size_include_paths = std::stoi(str_tmp); else if (count_word == 3) diff --git a/src/bs/bwconf_var.hpp b/src/bs/bwconf_var.hpp index d429e9a..6a842a8 100644 --- a/src/bs/bwconf_var.hpp +++ b/src/bs/bwconf_var.hpp @@ -35,6 +35,7 @@ #define DEBUG_FLAGS_LINKER_CXX "-fuse-ld=lld" #define DEFAULT_COMPILER_C "clang" +#define DEFAULT_COMPILER_CPP "clang++" #define PATH_TO_COMPILER_WIN1 "null" @@ -55,6 +56,7 @@ #define DEBUG_FLAGS_LINKER_CXX "-fuse-ld=lld" #define DEFAULT_COMPILER_C "clang" +#define DEFAULT_COMPILER_CPP "clang++" #define PATH_TO_COMPILER_UNIX_CL1 "null" diff --git a/src/bs/bwdepends_files.cpp b/src/bs/bwdepends_files.cpp index e2f3ef4..62fbd37 100644 --- a/src/bs/bwdepends_files.cpp +++ b/src/bs/bwdepends_files.cpp @@ -7,18 +7,37 @@ #include "bwdepends_files.hpp" +static bweas::logger log{"BWDEPENDS_FILES_SYSTEM"}; + bweas::bwdepends_files::depends_map &bweas::bwdepends_files::build_graphs_depends_files( - const std::vector &src_files, const std::vector &include_paths) { + const std::vector &src_files) { for (const auto &file : src_files) { - if (mdepends.find(file) == mdepends.end()) - mdepends[file] = build_graph_depends_file(file, include_paths); + try { + if (mdepends.find(file) == mdepends.end()) + mdepends[file] = build_graph_depends_file(file); + } + catch (std::exception &excp) { + log << bwtools::fatal + << (log_message(log_type::fatal) << "Failed to build a graph of file dependencies: " << excp.what()); + } + } + return mdepends; +} +bweas::bwdepends_files::depends_map &bweas::bwdepends_files::build_graphs_depends_file_v(const std::string &name_file) { + try { + mdepends[name_file] = build_graph_depends_file(name_file); } + catch (std::exception &excp) { + log << bwtools::fatal + << (log_message(log_type::fatal) << "Failed to build a graph of file dependencies: " << excp.what()); + } + return mdepends; } bweas::bwdepends_files::depends_map &bweas::bwdepends_files::build_graph_depends_file_string(std::string name_file, std::string depends_file) { auto it_depends_file = mdepends.find(mdepends[name_file].size() ? name_file : name_file); - i32t it = 0; + i32t it = 0; while ((it = depends_file.find("\n")) != depends_file.npos) { std::string name_dependences; for (u32t i = 0; i < it; ++i) @@ -38,3 +57,7 @@ std::string bweas::bwdepends_files::get_string_depends_file(std::string name_fil return str; } +void bweas::bwdepends_files::set_include_paths(const std::vector _include_paths) { + include_paths = _include_paths; +} + diff --git a/src/bs/bwdepends_files.hpp b/src/bs/bwdepends_files.hpp index 015d17c..b4ddbbc 100644 --- a/src/bs/bwdepends_files.hpp +++ b/src/bs/bwdepends_files.hpp @@ -32,25 +32,28 @@ class bwdepends_files { using depends_map = std::unordered_map; // Dependency graphs of source files are built - depends_map &build_graphs_depends_files(const std::vector &src_files, - const std::vector &include_paths); + depends_map &build_graphs_depends_files(const std::vector &src_files); + depends_map &build_graphs_depends_file_v(const std::string &name_file); + // depends_file - list of file dependencies(name_file) depends_map &build_graph_depends_file_string(std::string name_file, std::string depends_file); - depends_map &get_graphs_depends_files(); - public: + depends_map &get_graphs_depends_files(); // Returns all dependent files of the transmitted file as a string std::string get_string_depends_file(std::string name_file); + void set_include_paths(const std::vector _include_paths); + protected: - virtual std::unordered_set build_graph_depends_file(std::string_view name_file, - const std::vector &include_paths) = 0; + virtual std::unordered_set build_graph_depends_file(std::string_view name_file) = 0; protected: std::string language; std::string work_directory; + std::vector include_paths; + private: depends_map mdepends; }; diff --git a/src/bs/bwdepends_generator.hpp b/src/bs/bwdepends_generator.hpp index 91f66d4..12464a1 100644 --- a/src/bs/bwdepends_generator.hpp +++ b/src/bs/bwdepends_generator.hpp @@ -22,15 +22,13 @@ class bwdepends_generator : public bweas::bwdepends_files { ~bwdepends_generator() = default; public: - std::unordered_set build_graph_depends_file( - std::string_view name_file, const std::vector &include_paths) override final; + std::unordered_set build_graph_depends_file(std::string_view name_file) override final; private: std::shared_ptr generator; }; -std::unordered_set bweas::bwdepends_generator::build_graph_depends_file( - std::string_view name_file, const std::vector &include_paths) { +std::unordered_set bweas::bwdepends_generator::build_graph_depends_file(std::string_view name_file) { return generator->build_graph_depends_file(language, name_file, work_directory, include_paths); } } // namespace bweas diff --git a/src/bs/bwdepends_integral.cpp b/src/bs/bwdepends_integral.cpp new file mode 100644 index 0000000..d9de22f --- /dev/null +++ b/src/bs/bwdepends_integral.cpp @@ -0,0 +1,67 @@ +// +// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). +// you can view the license text at the link: +// +// ------------------------------------------ +// + +#include + +#include "bwdepends_integral.hpp" + +using namespace bweas; + +static logger log{"BWDEPENDS_FILES_SYSTEM[INTEGRAL]"}; + +std::unordered_set bweas::bwdepends_integral::build_graph_depends_file(std::string_view name_file) { + return build_graph_depends_file_c_cpp(name_file, include_paths); +} + +std::unordered_set bweas::bwdepends_integral::build_graph_depends_file_c_cpp( + std::string_view name_file, const std::vector &include_paths) { + std::unordered_set graph_depends_file; + + try { + bwtools::file_it file = bwtools::open_file(name_file); + std::string src_file = bwtools::read_file(bwtools::get_ref_file(file)); + bool is_system_header = 0; + + i32t pos_include = 0; + + src_file = std::regex_replace(src_file, std::regex{" "}, ""); + + while ((pos_include = src_file.find("#include")) != src_file.npos) { + if (auto pos_path = src_file.find_first_of("\"<"); pos_path == pos_include + 8) { + if (src_file[pos_path++] == '<') + is_system_header = 1; + + std::string include_file_path; + while (pos_path < src_file.size() && src_file[pos_path] != '\"' && src_file[pos_path] != '>') + include_file_path += src_file[pos_path++]; + + if (include_file_path.find(".hpp") == include_file_path.npos) + goto next_include; + + if (is_system_header) + include_file_path = bwfile::get_path_file(include_file_path, include_paths); + else + include_file_path = bwfile::get_path_file(include_file_path); + + graph_depends_file.insert(include_file_path); + graph_depends_file.merge(build_graph_depends_file_c_cpp(include_file_path, include_paths)); + + next_include: + src_file.erase(pos_include, pos_path + 1); + } + else + throw std::runtime_error("Invalid syntax"); + } + + bwtools::close_file(file); + } + catch (std::exception &excp) { + throw std::runtime_error(name_file.data() + std::string("->") + excp.what()); + } + + return graph_depends_file; +} diff --git a/src/bs/bwdepends_integral.hpp b/src/bs/bwdepends_integral.hpp index 96b0d74..bee9020 100644 --- a/src/bs/bwdepends_integral.hpp +++ b/src/bs/bwdepends_integral.hpp @@ -22,13 +22,12 @@ class bwdepends_integral : public bwdepends_files { ~bwdepends_integral() = default; public: - std::unordered_set build_graph_depends_file( - std::string_view name_file, const std::vector &include_paths) override final; + std::unordered_set build_graph_depends_file(std::string_view name_file) override final; + + private: + static std::unordered_set build_graph_depends_file_c_cpp( + std::string_view name_file, const std::vector &include_paths); }; } // namespace bweas -std::unordered_set bweas::bwdepends_integral::build_graph_depends_file( - std::string_view name_file, const std::vector &include_paths) { -} - #endif diff --git a/src/bs/bwgenerator_api.hpp b/src/bs/bwgenerator_api.hpp index 64dae64..41f968f 100644 --- a/src/bs/bwgenerator_api.hpp +++ b/src/bs/bwgenerator_api.hpp @@ -102,8 +102,8 @@ class base_generator : public gninterface::interface_generator { } public: - static inline base_generator *create_generator_int(func_generator, func_build_graph_depends_file, - func_get_input_files); + static inline base_generator *create_generator_int(func_build_graph_depends_file, func_get_input_files, + func_generator); static inline base_generator *create_generator_lua(std::string); public: @@ -119,11 +119,11 @@ class base_generator : public gninterface::interface_generator { // The class defines the API for internal generators, i.e. built into bweas as basic class integral_generator : public base_generator { - friend base_generator *base_generator::create_generator_int(func_generator, func_build_graph_depends_file, - func_get_input_files); + friend base_generator *base_generator::create_generator_int(func_build_graph_depends_file, func_get_input_files, + func_generator); private: - integral_generator(func_generator, func_build_graph_depends_file, func_get_input_files); + integral_generator(func_build_graph_depends_file, func_get_input_files, func_generator); ~integral_generator() = default; public: @@ -136,9 +136,9 @@ class integral_generator : public base_generator { gen_command generate_command(data_transfer &data_t) override final; private: - func_generator generator_p; func_build_graph_depends_file build_graph_depends_file_p; func_get_input_files get_input_files_p; + func_generator generate_p; }; // The class defines the API for generators written in lua and presented in bweas packages @@ -162,10 +162,9 @@ class lua_generator : public base_generator { bwlua::lua lua; }; -base_generator *base_generator::create_generator_int(func_generator generator, - func_build_graph_depends_file build_graph_depends_file, - func_get_input_files get_input_files) { - return (base_generator *)new integral_generator(generator, build_graph_depends_file, get_input_files); +base_generator *base_generator::create_generator_int(func_build_graph_depends_file build_graph_depends_file, + func_get_input_files get_input_files, func_generator generate) { + return (base_generator *)new integral_generator(build_graph_depends_file, get_input_files, generate); } base_generator *base_generator::create_generator_lua(std::string src_lua) { return (base_generator *)new lua_generator(src_lua); diff --git a/src/bs/bwgenerator_integral.cpp b/src/bs/bwgenerator_integral.cpp index e31e692..a6e6c7f 100644 --- a/src/bs/bwgenerator_integral.cpp +++ b/src/bs/bwgenerator_integral.cpp @@ -10,52 +10,216 @@ #include "tools/bwfile.hpp" using namespace bweas; -using namespace generator_api; -using namespace generator; static logger log{"BWGENERATOR[INTERNAL]"}; -integral_generator::integral_generator(func_generator _generator_p, - func_build_graph_depends_file _build_graph_depends_file_p, - func_get_input_files _get_input_files_p) { - generator_p = _generator_p; +generator_api::integral_generator::integral_generator(func_build_graph_depends_file _build_graph_depends_file_p, + func_get_input_files _get_input_files_p, + func_generator _generate_p) { build_graph_depends_file_p = _build_graph_depends_file_p; get_input_files_p = _get_input_files_p; + generate_p = _generate_p; } -void integral_generator::init() { +void generator_api::integral_generator::init() { } -void integral_generator::_delete() { +void generator_api::integral_generator::_delete() { delete this; } -std::unordered_set integral_generator::build_graph_depends_file(std::string_view language, - std::string_view name_file, - std::string_view work_directory, - std::vector include_paths) { +std::unordered_set generator_api::integral_generator::build_graph_depends_file( + std::string_view language, std::string_view name_file, std::string_view work_directory, + std::vector include_paths) { return build_graph_depends_file_p(language, name_file, work_directory, include_paths); } -void integral_generator::get_input_files(data_transfer &data_t) { +void generator_api::integral_generator::get_input_files(generator_api::data_transfer &data_t) { get_input_files_p(data_t); } -gen_command integral_generator::generate_command(data_transfer &data_t) { - generator::tools::parse_basic_args(*data_t.context->current_target, data_t.context->templates, - data_t.context->global_external_args); - return generator_p(data_t); +generator_api::gen_command generator_api::integral_generator::generate_command(generator_api::data_transfer &data_t) { + generator_tools::parse_basic_args(*data_t.context->current_target, data_t.context->templates, + data_t.context->global_external_args); + return generate_p(data_t); } -std::unordered_set bweas::generator::bwbuild_graph_depends_file(std::string_view language, - std::string_view name_file, - std::string_view work_directory, - std::vector include_paths) { - return {}; -} +void integral_generator::get_input_files(generator_api::data_transfer &data_t) { + for (const auto &target : data_t.context->out_targets) + for (const auto ¤t_template_name : target.prj.vec_templates) { + const auto ¤t_template = + std::find_if(data_t.context->templates.begin(), data_t.context->templates.end(), + [current_template_name](const var::struct_sb::template_command _template) { + return _template.name == current_template_name; + }); + const auto &call_component = + std::find_if(data_t.context->call_components.begin(), data_t.context->call_components.end(), + [current_template](const var::struct_sb::call_component &call_component) { + return call_component.name == current_template->name_call_component; + }); + for (auto &arg : current_template->args) { + if (arg.arg_t == var::struct_sb::template_command::arg::type::trgfield && + arg.str_arg.find(NAME_FIELD_PROJECT_SRC_FILES) == 0) { + std::string mask; + u32t it_str = arg.str_arg.find(":"); + if (it_str != arg.str_arg.npos) { + mask = arg.str_arg; + mask.erase(0, it_str + 1); + } + + if (std::atoll(mask.c_str()) != 0) { + if (std::atoll(mask.c_str()) == 1) { + for (u32t i = 0; + i < target.prj.src_files.size() && + std::find(data_t.ifiles[current_template->name].begin(), + data_t.ifiles[current_template->name].end(), + target.prj.src_files[i]) == data_t.ifiles[current_template->name].end(); + ++i) + data_t.ifiles[current_template->name].push_back(target.prj.src_files[i]); + arg.str_arg = "single"; + } + else { + for (u32t k = 0; + k < target.prj.src_files.size() && k < std::atoll(mask.c_str()) && + std::find(data_t.ifiles[current_template->name].begin(), + data_t.ifiles[current_template->name].end(), + target.prj.src_files[k]) == data_t.ifiles[current_template->name].end(); + ++k) + data_t.ifiles[current_template->name].push_back(target.prj.src_files[k]); + arg.str_arg = "all"; + } + } + else { + std::vector slc_files = bwfile::file_slc_mask(mask, target.prj.src_files); + for (u32t i = 0; i < slc_files.size() && + std::find(data_t.ifiles[current_template->name].begin(), + data_t.ifiles[current_template->name].end(), + slc_files[i]) == data_t.ifiles[current_template->name].end(); + ++i) + data_t.ifiles[current_template->name].push_back(target.prj.src_files[i]); + arg.str_arg = "all"; + } + } + else if (arg.arg_t == var::struct_sb::template_command::arg::type::features && + arg.str_arg.find(FEATURE_FIELD_BS_CURRENT_IF) == 0) { + for (u32t i = 0; i < target.prj.src_files.size() && + std::find(data_t.ifiles[current_template->name].begin(), + data_t.ifiles[current_template->name].end(), + target.prj.src_files[i]) == data_t.ifiles[current_template->name].end(); + ++i) -void bweas::generator::bwget_input_files(data_transfer &data_t) { + data_t.ifiles[current_template->name].push_back(target.prj.src_files[i]); + } + } + } } +generator_api::gen_command integral_generator::generate(generator_api::data_transfer &data_t) { + generator_api::gen_command command_s; + + std::map> internal_args_stack_tmp; + + bool generate_for_single_file = 0; + + for (const auto &target : data_t.context->out_targets) { + u32t count_use_ifiles = 0; + u32t i = 0; + + for (u32t j = 0; j < target.prj.vec_templates.size() || generate_for_single_file;) { + const auto ¤t_template_name = target.prj.vec_templates[j]; + const auto ¤t_template = + std::find_if(data_t.context->templates.begin(), data_t.context->templates.end(), + [current_template_name](const var::struct_sb::template_command _template) { + return _template.name == current_template_name; + }); + const auto &call_component = + std::find_if(data_t.context->call_components.begin(), data_t.context->call_components.end(), + [current_template](const var::struct_sb::call_component &call_component) { + return call_component.name == current_template->name_call_component; + }); + + std::string command = target.prj.path_compiler + " "; + std::string output_file = + generator_tools::get_name_output_file(call_component->pattern_ret_files, i, data_t.work_directory); -gen_command bweas::generator::bwgenerator(data_transfer &data_t) { - return std::map{{"test", "none"}}; + for (auto &arg : current_template->args) { + if ((arg.arg_t == var::struct_sb::template_command::arg::type::features && + arg.str_arg.find(FEATURE_FIELD_BS_CURRENT_IF) == 0) || + arg.arg_t == var::struct_sb::template_command::arg::type::trgfield) { + if (arg.str_arg == "single" || arg.str_arg.find(FEATURE_FIELD_BS_CURRENT_IF) == 0) { + generate_for_single_file = 1; + output_file = generator_tools::get_name_output_file(call_component->pattern_ret_files, + count_use_ifiles, data_t.work_directory); + if (generator_tools::should_uses_src_file( + data_t.ifiles[current_template_name][count_use_ifiles], + generator_tools::get_name_output_file(call_component->pattern_ret_files, + count_use_ifiles, data_t.work_directory), + data_t.dfiles[data_t.ifiles[current_template_name][count_use_ifiles]])) + command += data_t.ifiles[current_template_name][count_use_ifiles++]; + else { + internal_args_stack_tmp[current_template->returnable].push_back(output_file); + ++count_use_ifiles; + + command.clear(); + + break; + } + } + else + for (; count_use_ifiles < data_t.ifiles[current_template_name].size(); ++count_use_ifiles) + if (generator_tools::should_uses_src_file( + data_t.ifiles[current_template_name][count_use_ifiles], + generator_tools::get_name_output_file(call_component->pattern_ret_files, + count_use_ifiles, data_t.work_directory), + data_t.dfiles[data_t.ifiles[current_template_name][count_use_ifiles]])) + command += data_t.ifiles[current_template_name][count_use_ifiles] + " "; + } + else if (arg.arg_t == var::struct_sb::template_command::arg::type::features && + arg.str_arg.find(FEATURE_FIELD_BS_CURRENT_OF) == 0) { + if (current_template->returnable == target_t_str(target.target_t)) + command += output_file; + else { + if (generate_for_single_file) { + internal_args_stack_tmp[current_template->returnable].push_back(output_file); + command += output_file; + } + else + for (u32t k = 0; k < count_use_ifiles; ++k) { + internal_args_stack_tmp[current_template->returnable].push_back( + generator_tools::get_name_output_file(call_component->pattern_ret_files, k, + data_t.work_directory)); + command += internal_args_stack_tmp + [current_template->returnable] + [internal_args_stack_tmp[current_template->returnable].size() - 1] + + " "; + } + } + ++i; + } + else if (arg.arg_t == var::struct_sb::template_command::arg::type::internal) + for (u32t k = 0; k < internal_args_stack_tmp[arg.str_arg].size(); ++k) + command += internal_args_stack_tmp[arg.str_arg][k] + " "; + else if (arg.arg_t == var::struct_sb::template_command::arg::type::string) + command += arg.str_arg; + + if (command[command.size() - 1] != ' ') + command += " "; + } + if (command.empty()) + log << (log_message(log_type::msg) << "Skipped command generation for the file: " << output_file); + else { + log << (log_message(log_type::msg) << "The command has been generated: " << command); + command_s[output_file] = command; + } + + if (generate_for_single_file && count_use_ifiles < data_t.ifiles[current_template_name].size()) + continue; + + generate_for_single_file = 0; + count_use_ifiles = 0; + i = 0; + + ++j; + } + } + return command_s; } + diff --git a/src/bs/bwgenerator_integral.hpp b/src/bs/bwgenerator_integral.hpp index eaedc7d..1404f2e 100644 --- a/src/bs/bwgenerator_integral.hpp +++ b/src/bs/bwgenerator_integral.hpp @@ -14,15 +14,17 @@ #include "bwgenerator_api.hpp" namespace bweas { -namespace generator { +class integral_generator { + public: + integral_generator() = delete; -extern std::unordered_set bwbuild_graph_depends_file(std::string_view, std::string_view, std::string_view, - std::vector); + public: + static void get_input_files(bweas::generator_api::data_transfer &data_t); + // First and basic template-based command generator + static generator_api::gen_command generate(bweas::generator_api::data_transfer &data_t); -extern void bwget_input_files(bweas::generator_api::data_transfer &); -// First and basic template-based command generator -extern bweas::generator_api::gen_command bwgenerator(bweas::generator_api::data_transfer &); -} // namespace generator + public: +}; } // namespace bweas #endif diff --git a/src/bs/bwgenerator_lua.cpp b/src/bs/bwgenerator_lua.cpp index be89dbd..e55f3dd 100644 --- a/src/bs/bwgenerator_lua.cpp +++ b/src/bs/bwgenerator_lua.cpp @@ -72,8 +72,8 @@ void lua_generator::get_input_files(data_transfer &data_t) { } gen_command lua_generator::generate_command(data_transfer &data_t) { - generator::tools::parse_basic_args(*data_t.context->current_target, data_t.context->templates, - data_t.context->global_external_args); + generator_tools::parse_basic_args(*data_t.context->current_target, data_t.context->templates, + data_t.context->global_external_args); std::vector> tcmd_s_vec; for (const auto &_template : data_t.context->templates) diff --git a/src/bs/bwgntools.cpp b/src/bs/bwgntools.cpp index b8670ee..0a70b35 100644 --- a/src/bs/bwgntools.cpp +++ b/src/bs/bwgntools.cpp @@ -9,7 +9,7 @@ using namespace bweas; -std::string generator::tools::get_name_output_file(std::string pattern_file, u32t index, std::string dir_work_endv) { +std::string generator_tools::get_name_output_file(std::string pattern_file, u32t index, std::string dir_work_endv) { if (pattern_file.find(".") == pattern_file.npos) return dir_work_endv + "/" + pattern_file + std::to_string(index); std::string name_output_file_curr = pattern_file, extension_output_file_curr = pattern_file; @@ -20,8 +20,23 @@ std::string generator::tools::get_name_output_file(std::string pattern_file, u32 return dir_work_endv + "/" + name_output_file_curr + extension_output_file_curr; } -void generator::tools::parse_basic_args(const var::struct_sb::target_out &target, - bwqueue_templates &target_queue_templates, const bwargs &global_extern_args) { +bool generator_tools::should_uses_src_file(std::string_view src_file, std::string_view output_file, + const std::unordered_set &dfiles) { + if (std::filesystem::last_write_time(CACHE_FILE) > std::filesystem::last_write_time(output_file)) + return 1; + else if (!std::filesystem::is_regular_file(output_file) || + std::filesystem::last_write_time(output_file) < std::filesystem::last_write_time(src_file)) + return 1; + + for (const auto &dfile : dfiles) + if (std::filesystem::last_write_time(output_file) < std::filesystem::last_write_time(dfile)) + return 1; + + return 0; +} + +void generator_tools::parse_basic_args(const var::struct_sb::target_out &target, + bwqueue_templates &target_queue_templates, const bwargs &global_extern_args) { for (auto &trg_template : target_queue_templates) { for (u32t i = 0; i < trg_template.args.size(); ++i) { var::struct_sb::template_command::arg ¤t_arg = trg_template.args[i]; diff --git a/src/bs/bwgntools.hpp b/src/bs/bwgntools.hpp index 6c2f3e4..02d29d6 100644 --- a/src/bs/bwgntools.hpp +++ b/src/bs/bwgntools.hpp @@ -9,27 +9,33 @@ #define BWGNTOOLS__H #include +#include #include namespace bweas { -namespace generator { -namespace tools { +class generator_tools { + public: + generator_tools() = delete; -// Generates a file name based on the pattern and the passed index of the given file -extern std::string get_name_output_file(std::string pattern_file, u32t index, std::string dir_work_endv); + public: + // Generates a file name based on the pattern and the passed index of the given file. + static std::string get_name_output_file(std::string pattern_file, u32t index, std::string dir_work_endv); -// Parses all the basic arguments for further template command generation -// Types of arguments that will be parsed: -// 1. extglobal -// 2. trgfield(except T_PROJECT_SRC_FILES) -extern void parse_basic_args(const var::struct_sb::target_out &target, bwqueue_templates &target_queue_templates, - const bwargs &global_extern_args); + // Determines, based on the time of creation or modification of the file and its dependencies, whether it should be + // passed to the generator. + static bool should_uses_src_file(std::string_view src_file, std::string_view output_file, + const std::unordered_set &dfiles); -} // namespace tools + // Parses all the basic arguments for further template command generation. + // Types of arguments that will be parsed: + // 1. extglobal + // 2. trgfield(except T_PROJECT_SRC_FILES) + static void parse_basic_args(const var::struct_sb::target_out &target, bwqueue_templates &target_queue_templates, + const bwargs &global_extern_args); +}; -} // namespace generator } // namespace bweas #endif diff --git a/src/bs/bwluatools.cpp b/src/bs/bwluatools.cpp index ff75e49..a4832f3 100644 --- a/src/bs/bwluatools.cpp +++ b/src/bs/bwluatools.cpp @@ -214,7 +214,7 @@ int bwluatools::set_var(lua_State *L) { int bwluatools::get_name_output_file_lua(lua_State *L) { bwlua::tools::push_stack( L, - generator::tools::get_name_output_file(lua_tostring(L, -3), lua_tointeger(L, -2), lua_tostring(L, -1)).c_str()); + generator_tools::get_name_output_file(lua_tostring(L, -3), lua_tointeger(L, -2), lua_tostring(L, -1)).c_str()); return 1; } int bwluatools::file_slc_mask_lua(lua_State *L) { diff --git a/src/bs/bwluatools.hpp b/src/bs/bwluatools.hpp index 3c786d0..ebcf81d 100644 --- a/src/bs/bwluatools.hpp +++ b/src/bs/bwluatools.hpp @@ -22,6 +22,9 @@ class bwluatools; // A class providing tools for simplified interaction between bweas and lua structures class bweas::bwluatools { + public: + bwluatools() = delete; + public: template using ref = bwlua::lua::ref; diff --git a/src/bs/bwtools.hpp b/src/bs/bwtools.hpp index 15d9722..f5d788e 100644 --- a/src/bs/bwtools.hpp +++ b/src/bs/bwtools.hpp @@ -36,6 +36,9 @@ extern bwtools _bwtools; // A base class that implements many auxiliary functions class bweas::bwtools { + public: + bwtools() = delete; + public: struct file { struct mode_file { diff --git a/src/bs/lang/static_struct.hpp b/src/bs/lang/static_struct.hpp index 900db11..31f4dac 100644 --- a/src/bs/lang/static_struct.hpp +++ b/src/bs/lang/static_struct.hpp @@ -196,7 +196,7 @@ struct project { std::string language; - std::string path_compiler{DEFAULT_COMPILER_C}, path_linker{DEFAULT_COMPILER_C}; + std::string path_compiler{DEFAULT_COMPILER_CPP}, path_linker{DEFAULT_COMPILER_CPP}; std::string rflags_compiler{RELEASE_FLAGS_COMPILER_CPP}, rflags_linker{RELEASE_FLAGS_LINKER_CXX}; std::string dflags_compiler{DEBUG_FLAGS_COMPILER_CPP}, dflags_linker{DEBUG_FLAGS_LINKER_CXX}; i32t standart_c{98}, standart_cpp{14}; @@ -204,7 +204,7 @@ struct project { bool use_it_templates{0}; std::vector src_files; - std::vector include_paths{"null"}; + std::vector include_paths{"/usr/include", "/usr/local/include"}; std::vector vec_templates{"null"}; std::map custom_ext_fields{{"null", ""}}; diff --git a/src/bs/tools/bwexception.hpp b/src/bs/tools/bwexception.hpp deleted file mode 100644 index 15470df..0000000 --- a/src/bs/tools/bwexception.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// -// BWEAS is distributed under the gnu general public license 2.0 (gpl-2.0). -// you can view the license text at the link: -// -// ------------------------------------------ -// - -#ifndef EXCEPTION__H -#define EXCEPTION__H - -#include -#include - -namespace bwexception { - -// Base exception class bweas, which inherits from std::exception. -// All child exception classes of bweas must inherit from it. -class bweas_exception : std::exception { - public: - bweas_exception(std::string _assist_err) noexcept : assist_err(_assist_err) { - } - ~bweas_exception() noexcept = default; - - public: - const char *what() const noexcept { - return ""; - } - - const char *get_assist_err() const noexcept { - return assist_err.c_str(); - } - - // NAME_CLASS_ERROR_000 - // For example: BWS000 - std::string assist_err; -}; -} // namespace bwexception - -#endif diff --git a/src/bs/tools/bwfile.hpp b/src/bs/tools/bwfile.hpp index 1a6dbab..bd1116b 100644 --- a/src/bs/tools/bwfile.hpp +++ b/src/bs/tools/bwfile.hpp @@ -9,17 +9,29 @@ #define BWFILE__H #include +#include #include #include #include -namespace bwfile { +class bwfile { + public: + bwfile() = delete; -// Creates an array of file names based on the mask -// passed to the function and an array of all files. -// ### The syntax is fully compliant with the glob() standard. -static std::vector file_slc_mask(std::string mask, const std::vector &files) { + public: + // Creates an array of file names based on the mask + // passed to the function and an array of all files. + // ### The syntax is fully compliant with the glob() standard. + static inline std::vector file_slc_mask(std::string mask, const std::vector &files); + + // Returns the absolute path to an existing file, considering the current directory. + static inline std::string get_path_file(std::string name_file); + // Returns the absolute path to an existing file, considering all possible paths, including the current directory. + static inline std::string get_path_file(std::string name_file, const std::vector &possible_paths); +}; + +std::vector bwfile::file_slc_mask(std::string mask, const std::vector &files) { std::vector slc_files; std::vector masks; @@ -94,6 +106,33 @@ static std::vector file_slc_mask(std::string mask, const std::vecto return slc_files; } -} // namespace bwfile +std::string bwfile::get_path_file(std::string name_file) { + if (auto path_file = std::filesystem::weakly_canonical(std::filesystem::current_path() / name_file); + std::filesystem::is_regular_file(path_file)) + return path_file.string(); + + return {}; +} + +std::string bwfile::get_path_file(std::string name_file, const std::vector &possible_paths) { + if (auto path_file = get_path_file(name_file); !path_file.empty()) + return path_file; + + std::filesystem::path current_path_tmp = std::filesystem::current_path(); + std::filesystem::path find_path_file; + + for (const auto &path : possible_paths) { + std::filesystem::current_path(std::filesystem::weakly_canonical(path)); + if (auto path_file = std::filesystem::weakly_canonical(std::filesystem::current_path() / name_file); + std::filesystem::is_regular_file(path_file)) { + find_path_file = path_file; + break; + } + } + + std::filesystem::current_path(current_path_tmp); + + return find_path_file.string(); +} #endif diff --git a/src/bs/tools/bwlua.hpp b/src/bs/tools/bwlua.hpp index 56c980e..a1d1975 100644 --- a/src/bs/tools/bwlua.hpp +++ b/src/bs/tools/bwlua.hpp @@ -77,8 +77,6 @@ template inline T call_function(lua_State *L, int count_param); // A wrapper class for luajit. // It contains basic functions for interacting with lua scripts. -// The class is thread safe provided that you do not use __mutex functions. -// All functions without the __nmutex prefix block the RAII-style mutex. // If an error occurs in any function, an exception is thrown, which at best should be handled! // If a function (any) sees that lua_state is not defined, it will not do anything. class lua { @@ -330,7 +328,6 @@ class lua { template T call_function(std::string name_func, Types... param) { if (!is_created()) return T{}; - lua_settop(L, 0); lua_getglobal(L, name_func.data()); try { return call_symbol(param...); From 46acb98d90b2fe7c97cc51e8b357db270d81aeba Mon Sep 17 00:00:00 2001 From: svec1 Date: Fri, 6 Jun 2025 22:28:38 +0000 Subject: [PATCH 07/38] code refactoring, add doxygen docs --- .gitignore | 2 + CMakeLists.txt | 1 + Doxyfile | 2970 +++++++++++++++++ README.md | 1 - docs/doxygen/html/annotated.html | 155 + docs/doxygen/html/annotated_dup.js | 34 + docs/doxygen/html/bc_s.png | Bin 0 -> 676 bytes docs/doxygen/html/bc_sd.png | Bin 0 -> 635 bytes docs/doxygen/html/bw__defs_8hpp_source.html | 197 ++ .../html/bwbuild__sys_8hpp_source.html | 235 ++ .../html/bwcache__api_8hpp_source.html | 241 ++ .../doxygen/html/bwconf__var_8hpp_source.html | 183 + .../html/bwdepends__files_8hpp_source.html | 181 + .../bwdepends__generator_8hpp_source.html | 156 + .../html/bwdepends__integral_8hpp_source.html | 153 + .../html/bwgenerator__api_8hpp_source.html | 309 ++ .../bwgenerator__integral_8hpp_source.html | 151 + docs/doxygen/html/bwgntools_8hpp_source.html | 161 + docs/doxygen/html/bwlang_8hpp_source.html | 327 ++ docs/doxygen/html/bwlogger_8hpp_source.html | 211 ++ docs/doxygen/html/bwluatools_8hpp_source.html | 194 ++ .../html/bwmacros__platform_8h_source.html | 151 + docs/doxygen/html/bwmodule_8hpp_source.html | 166 + docs/doxygen/html/bwpackage_8hpp_source.html | 238 ++ docs/doxygen/html/bwtools_8hpp_source.html | 308 ++ docs/doxygen/html/bwtype_8h_source.html | 136 + .../html/classbweas_1_1bwbuilder-members.html | 139 + .../doxygen/html/classbweas_1_1bwbuilder.html | 374 +++ docs/doxygen/html/classbweas_1_1bwbuilder.js | 19 + ...lassbweas_1_1bwdepends__files-members.html | 134 + .../html/classbweas_1_1bwdepends__files.html | 190 ++ .../html/classbweas_1_1bwdepends__files.png | Bin 0 -> 1036 bytes ...bweas_1_1bwdepends__generator-members.html | 136 + .../classbweas_1_1bwdepends__generator.html | 212 ++ .../classbweas_1_1bwdepends__generator.png | Bin 0 -> 723 bytes ...sbweas_1_1bwdepends__integral-members.html | 136 + .../classbweas_1_1bwdepends__integral.html | 213 ++ .../classbweas_1_1bwdepends__integral.png | Bin 0 -> 712 bytes .../html/classbweas_1_1bwlang-members.html | 132 + docs/doxygen/html/classbweas_1_1bwlang.html | 167 + .../classbweas_1_1bwluatools-members.html | 144 + .../html/classbweas_1_1bwluatools.html | 206 ++ .../classbweas_1_1bwmodule__mg-members.html | 124 + .../html/classbweas_1_1bwmodule__mg.html | 145 + .../html/classbweas_1_1bwmodule__mg.js | 4 + .../html/classbweas_1_1bwpackage-members.html | 128 + .../doxygen/html/classbweas_1_1bwpackage.html | 166 + docs/doxygen/html/classbweas_1_1bwpackage.js | 5 + .../html/classbweas_1_1bwtools-members.html | 138 + docs/doxygen/html/classbweas_1_1bwtools.html | 190 ++ docs/doxygen/html/classbweas_1_1bwtools.js | 4 + ..._1cache__api_1_1base__bwcache-members.html | 128 + ...sbweas_1_1cache__api_1_1base__bwcache.html | 171 + ...ssbweas_1_1cache__api_1_1base__bwcache.png | Bin 0 -> 1304 bytes ..._1cache__api_1_1fast__bwcache-members.html | 124 + ...sbweas_1_1cache__api_1_1fast__bwcache.html | 229 ++ ...ssbweas_1_1cache__api_1_1fast__bwcache.png | Bin 0 -> 774 bytes ..._1cache__api_1_1json__bwcache-members.html | 124 + ...sbweas_1_1cache__api_1_1json__bwcache.html | 229 ++ ...ssbweas_1_1cache__api_1_1json__bwcache.png | Bin 0 -> 782 bytes ...1_1cache__api_1_1lua__bwcache-members.html | 124 + ...ssbweas_1_1cache__api_1_1lua__bwcache.html | 229 ++ ...assbweas_1_1cache__api_1_1lua__bwcache.png | Bin 0 -> 774 bytes ...rator__api_1_1base__generator-members.html | 133 + ..._1_1generator__api_1_1base__generator.html | 177 + ...s_1_1generator__api_1_1base__generator.png | Bin 0 -> 2238 bytes ...rface_1_1interface__generator-members.html | 127 + ..._1gninterface_1_1interface__generator.html | 157 + ...1_1gninterface_1_1interface__generator.png | Bin 0 -> 2238 bytes ...r__api_1_1integral__generator-members.html | 134 + ...generator__api_1_1integral__generator.html | 330 ++ ...1generator__api_1_1integral__generator.png | Bin 0 -> 1616 bytes ...erator__api_1_1lua__generator-members.html | 134 + ...s_1_1generator__api_1_1lua__generator.html | 330 ++ ...as_1_1generator__api_1_1lua__generator.png | Bin 0 -> 1580 bytes ...lassbweas_1_1generator__tools-members.html | 124 + .../html/classbweas_1_1generator__tools.html | 138 + ...sbweas_1_1integral__generator-members.html | 123 + .../classbweas_1_1integral__generator.html | 135 + .../classbweas_1_1log__message-members.html | 123 + .../html/classbweas_1_1log__message.html | 140 + .../html/classbweas_1_1logger-members.html | 130 + docs/doxygen/html/classbweas_1_1logger.html | 163 + docs/doxygen/html/classes.html | 147 + docs/doxygen/html/clipboard.js | 61 + docs/doxygen/html/closed.png | Bin 0 -> 132 bytes docs/doxygen/html/cookie.js | 58 + .../dir_68267d1309a1af8e8297ef4c3efbcdba.html | 124 + .../dir_68267d1309a1af8e8297ef4c3efbcdba.js | 4 + .../dir_9a2503315d2c62a47b870cbc92f226de.html | 158 + .../dir_9a2503315d2c62a47b870cbc92f226de.js | 21 + docs/doxygen/html/doc.svg | 12 + docs/doxygen/html/docd.svg | 12 + docs/doxygen/html/doxygen-awesome.css | 2683 +++++++++++++++ docs/doxygen/html/doxygen.css | 2255 +++++++++++++ docs/doxygen/html/doxygen.svg | 28 + docs/doxygen/html/doxygen_crawl.html | 118 + docs/doxygen/html/dynsections.js | 198 ++ docs/doxygen/html/files.html | 141 + docs/doxygen/html/files_dup.js | 4 + docs/doxygen/html/folderclosed.svg | 11 + docs/doxygen/html/folderclosedd.svg | 11 + docs/doxygen/html/folderopen.svg | 17 + docs/doxygen/html/folderopend.svg | 12 + docs/doxygen/html/functions.html | 130 + docs/doxygen/html/functions_enum.html | 117 + docs/doxygen/html/functions_eval.html | 120 + docs/doxygen/html/functions_func.html | 124 + docs/doxygen/html/functions_vars.html | 117 + docs/doxygen/html/hierarchy.html | 151 + docs/doxygen/html/hierarchy.js | 37 + docs/doxygen/html/index.html | 118 + docs/doxygen/html/jquery.js | 204 ++ docs/doxygen/html/md_README.html | 193 ++ docs/doxygen/html/minus.svg | 8 + docs/doxygen/html/minusd.svg | 8 + docs/doxygen/html/nav_f.png | Bin 0 -> 153 bytes docs/doxygen/html/nav_fd.png | Bin 0 -> 169 bytes docs/doxygen/html/nav_g.png | Bin 0 -> 95 bytes docs/doxygen/html/nav_h.png | Bin 0 -> 98 bytes docs/doxygen/html/nav_hd.png | Bin 0 -> 114 bytes docs/doxygen/html/navtree.css | 149 + docs/doxygen/html/navtree.js | 483 +++ docs/doxygen/html/navtreedata.js | 52 + docs/doxygen/html/navtreeindex0.js | 79 + docs/doxygen/html/open.png | Bin 0 -> 123 bytes docs/doxygen/html/pages.html | 122 + docs/doxygen/html/plus.svg | 9 + docs/doxygen/html/plusd.svg | 9 + docs/doxygen/html/resize.js | 147 + docs/doxygen/html/search/all_0.js | 17 + docs/doxygen/html/search/all_1.js | 9 + docs/doxygen/html/search/all_2.js | 5 + docs/doxygen/html/search/all_3.js | 5 + docs/doxygen/html/search/all_4.js | 7 + docs/doxygen/html/search/all_5.js | 4 + docs/doxygen/html/search/all_6.js | 6 + docs/doxygen/html/search/all_7.js | 4 + docs/doxygen/html/search/all_8.js | 7 + docs/doxygen/html/search/all_9.js | 6 + docs/doxygen/html/search/all_a.js | 4 + docs/doxygen/html/search/all_b.js | 4 + docs/doxygen/html/search/classes_0.js | 15 + docs/doxygen/html/search/classes_1.js | 5 + docs/doxygen/html/search/classes_2.js | 5 + docs/doxygen/html/search/classes_3.js | 5 + docs/doxygen/html/search/classes_4.js | 5 + docs/doxygen/html/search/classes_5.js | 5 + docs/doxygen/html/search/classes_6.js | 4 + docs/doxygen/html/search/classes_7.js | 7 + docs/doxygen/html/search/classes_8.js | 5 + docs/doxygen/html/search/close.svg | 18 + docs/doxygen/html/search/enums_0.js | 4 + docs/doxygen/html/search/enumvalues_0.js | 5 + docs/doxygen/html/search/enumvalues_1.js | 5 + docs/doxygen/html/search/enumvalues_2.js | 4 + docs/doxygen/html/search/functions_0.js | 4 + docs/doxygen/html/search/functions_1.js | 4 + docs/doxygen/html/search/functions_2.js | 5 + docs/doxygen/html/search/functions_3.js | 4 + docs/doxygen/html/search/functions_4.js | 4 + docs/doxygen/html/search/functions_5.js | 4 + docs/doxygen/html/search/functions_6.js | 4 + docs/doxygen/html/search/mag.svg | 24 + docs/doxygen/html/search/mag_d.svg | 24 + docs/doxygen/html/search/mag_sel.svg | 31 + docs/doxygen/html/search/mag_seld.svg | 31 + docs/doxygen/html/search/pages_0.js | 4 + docs/doxygen/html/search/search.css | 286 ++ docs/doxygen/html/search/search.js | 694 ++++ docs/doxygen/html/search/searchdata.js | 30 + docs/doxygen/html/search/variables_0.js | 4 + docs/doxygen/html/splitbar.png | Bin 0 -> 314 bytes docs/doxygen/html/splitbard.png | Bin 0 -> 282 bytes .../structbweas_1_1bw__context-members.html | 125 + .../html/structbweas_1_1bw__context.html | 143 + ...eas_1_1bwmodule__mg_1_1module-members.html | 124 + ...structbweas_1_1bwmodule__mg_1_1module.html | 144 + ...tbweas_1_1bwpackage_1_1config-members.html | 124 + .../structbweas_1_1bwpackage_1_1config.html | 148 + .../structbweas_1_1bwpackage_1_1config.js | 5 + ...ckage_1_1config_1_1cache__lua-members.html | 124 + ..._1_1bwpackage_1_1config_1_1cache__lua.html | 141 + ...e_1_1config_1_1generator__lua-members.html | 126 + ...bwpackage_1_1config_1_1generator__lua.html | 147 + ...wpackage_1_1data__bw__package-members.html | 123 + ...eas_1_1bwpackage_1_1data__bw__package.html | 137 + ...tructbweas_1_1bwtools_1_1file-members.html | 134 + .../html/structbweas_1_1bwtools_1_1file.html | 174 + .../html/structbweas_1_1bwtools_1_1file.js | 4 + ...bwtools_1_1file_1_1mode__file-members.html | 123 + ...weas_1_1bwtools_1_1file_1_1mode__file.html | 147 + ...erator__api_1_1data__transfer-members.html | 125 + ...s_1_1generator__api_1_1data__transfer.html | 147 + docs/doxygen/html/sync_off.png | Bin 0 -> 853 bytes docs/doxygen/html/sync_on.png | Bin 0 -> 845 bytes docs/doxygen/html/tab_a.png | Bin 0 -> 142 bytes docs/doxygen/html/tab_ad.png | Bin 0 -> 135 bytes docs/doxygen/html/tab_b.png | Bin 0 -> 169 bytes docs/doxygen/html/tab_bd.png | Bin 0 -> 173 bytes docs/doxygen/html/tab_h.png | Bin 0 -> 177 bytes docs/doxygen/html/tab_hd.png | Bin 0 -> 180 bytes docs/doxygen/html/tab_s.png | Bin 0 -> 184 bytes docs/doxygen/html/tab_sd.png | Bin 0 -> 188 bytes docs/doxygen/html/tabs.css | 1 + docs/doxygen/latex/Makefile | 42 + docs/doxygen/latex/annotated.tex | 33 + docs/doxygen/latex/bw__defs_8hpp_source.tex | 82 + .../latex/bwbuild__sys_8hpp_source.tex | 103 + .../latex/bwcache__api_8hpp_source.tex | 118 + .../doxygen/latex/bwconf__var_8hpp_source.tex | 71 + .../latex/bwdepends__files_8hpp_source.tex | 67 + .../bwdepends__generator_8hpp_source.tex | 41 + .../latex/bwdepends__integral_8hpp_source.tex | 39 + .../latex/bwgenerator__api_8hpp_source.tex | 182 + .../bwgenerator__integral_8hpp_source.tex | 36 + docs/doxygen/latex/bwgntools_8hpp_source.tex | 47 + docs/doxygen/latex/bwlang_8hpp_source.tex | 212 ++ docs/doxygen/latex/bwlogger_8hpp_source.tex | 93 + docs/doxygen/latex/bwluatools_8hpp_source.tex | 79 + .../latex/bwmacros__platform_8h_source.tex | 39 + docs/doxygen/latex/bwmodule_8hpp_source.tex | 50 + docs/doxygen/latex/bwpackage_8hpp_source.tex | 113 + docs/doxygen/latex/bwtools_8hpp_source.tex | 188 ++ docs/doxygen/latex/bwtype_8h_source.tex | 24 + .../doxygen/latex/classbweas_1_1bwbuilder.tex | 188 ++ .../latex/classbweas_1_1bwdepends__files.eps | 203 ++ .../latex/classbweas_1_1bwdepends__files.tex | 65 + .../classbweas_1_1bwdepends__generator.eps | 197 ++ .../classbweas_1_1bwdepends__generator.tex | 68 + .../classbweas_1_1bwdepends__integral.eps | 197 ++ .../classbweas_1_1bwdepends__integral.tex | 69 + docs/doxygen/latex/classbweas_1_1bwlang.tex | 46 + .../latex/classbweas_1_1bwluatools.tex | 83 + .../latex/classbweas_1_1bwmodule__mg.tex | 25 + .../doxygen/latex/classbweas_1_1bwpackage.tex | 45 + docs/doxygen/latex/classbweas_1_1bwtools.tex | 70 + ...ssbweas_1_1cache__api_1_1base__bwcache.eps | 207 ++ ...ssbweas_1_1cache__api_1_1base__bwcache.tex | 46 + ...ssbweas_1_1cache__api_1_1fast__bwcache.eps | 197 ++ ...ssbweas_1_1cache__api_1_1fast__bwcache.tex | 59 + ...ssbweas_1_1cache__api_1_1json__bwcache.eps | 197 ++ ...ssbweas_1_1cache__api_1_1json__bwcache.tex | 59 + ...assbweas_1_1cache__api_1_1lua__bwcache.eps | 197 ++ ...assbweas_1_1cache__api_1_1lua__bwcache.tex | 59 + ...s_1_1generator__api_1_1base__generator.eps | 209 ++ ...s_1_1generator__api_1_1base__generator.tex | 49 + ...1_1gninterface_1_1interface__generator.eps | 209 ++ ...1_1gninterface_1_1interface__generator.tex | 34 + ...1generator__api_1_1integral__generator.eps | 203 ++ ...1generator__api_1_1integral__generator.tex | 108 + ...as_1_1generator__api_1_1lua__generator.eps | 203 ++ ...as_1_1generator__api_1_1lua__generator.tex | 108 + .../latex/classbweas_1_1generator__tools.tex | 20 + .../classbweas_1_1integral__generator.tex | 17 + .../latex/classbweas_1_1log__message.tex | 20 + docs/doxygen/latex/classbweas_1_1logger.tex | 44 + docs/doxygen/latex/doxygen.sty | 714 ++++ docs/doxygen/latex/etoc_doxygen.sty | 2178 ++++++++++++ docs/doxygen/latex/files.tex | 21 + docs/doxygen/latex/hierarchy.tex | 41 + docs/doxygen/latex/longtable_doxygen.sty | 459 +++ docs/doxygen/latex/md_README.tex | 112 + docs/doxygen/latex/refman.tex | 300 ++ .../latex/structbweas_1_1bw__context.tex | 25 + .../structbweas_1_1bwmodule__mg_1_1module.tex | 25 + .../structbweas_1_1bwpackage_1_1config.tex | 29 + ...s_1_1bwpackage_1_1config_1_1cache__lua.tex | 22 + ...1bwpackage_1_1config_1_1generator__lua.tex | 28 + ...weas_1_1bwpackage_1_1data__bw__package.tex | 19 + .../latex/structbweas_1_1bwtools_1_1file.tex | 54 + ...bweas_1_1bwtools_1_1file_1_1mode__file.tex | 31 + ...as_1_1generator__api_1_1data__transfer.tex | 28 + docs/doxygen/latex/tabu_doxygen.sty | 2557 ++++++++++++++ src/bs/bw_defs.hpp | 78 +- src/bs/bwaliases.hpp | 23 + src/bs/bwbuild_sys.cpp | 98 +- src/bs/bwbuild_sys.hpp | 158 +- src/bs/bwcache_api.hpp | 41 +- src/bs/bwcache_fast.cpp | 134 +- src/bs/bwcache_json.cpp | 10 +- src/bs/bwcache_lua.cpp | 72 +- src/bs/bwconf_var.hpp | 4 +- src/bs/bwdepends_files.cpp | 21 +- src/bs/bwdepends_files.hpp | 35 +- src/bs/bwdepends_generator.hpp | 12 +- src/bs/bwdepends_integral.cpp | 16 +- src/bs/bwdepends_integral.hpp | 7 +- src/bs/bwgenerator_api.hpp | 55 +- src/bs/bwgenerator_integral.cpp | 49 +- src/bs/bwgenerator_integral.hpp | 4 +- src/bs/bwgenerator_lua.cpp | 63 +- src/bs/bwgntools.cpp | 26 +- src/bs/bwgntools.hpp | 17 +- src/bs/bwlang.hpp | 84 +- src/bs/bwlogger.cpp | 4 +- src/bs/bwlogger.hpp | 14 +- src/bs/bwluatools.cpp | 205 +- src/bs/bwluatools.hpp | 41 +- src/bs/bwmacros_platform.h | 4 +- src/bs/bwmodule.cpp | 12 +- src/bs/bwmodule.hpp | 7 +- src/bs/bwpackage.cpp | 94 +- src/bs/bwpackage.hpp | 63 +- src/bs/bwtools.cpp | 2 +- src/bs/bwtools.hpp | 11 +- src/bs/bwtype.h | 18 - src/bs/lang/expression.hpp | 41 +- src/bs/lang/interpreter.cpp | 13 +- src/bs/lang/interpreter.hpp | 6 +- src/bs/lang/lexer.l | 11 +- src/bs/lang/parser.y | 6 +- src/bs/lang/scope.hpp | 114 +- src/bs/lang/semantic_an.cpp | 87 +- src/bs/lang/semantic_an.hpp | 2 +- src/bs/lang/static_linking_func.cpp | 732 +--- src/bs/lang/static_linking_func.hpp | 3 - src/bs/lang/static_struct.hpp | 206 +- src/bs/lang/var.hpp | 46 +- src/bs/tools/bwfile.hpp | 32 +- src/bs/tools/bwlz4.hpp | 8 +- src/bs/tools/bwtemplates.hpp | 389 +++ src/bs/tools/call_cmd.hpp | 14 +- src/bweas.cpp | 4 +- 324 files changed, 39537 insertions(+), 1630 deletions(-) create mode 100644 Doxyfile create mode 100644 docs/doxygen/html/annotated.html create mode 100644 docs/doxygen/html/annotated_dup.js create mode 100644 docs/doxygen/html/bc_s.png create mode 100644 docs/doxygen/html/bc_sd.png create mode 100644 docs/doxygen/html/bw__defs_8hpp_source.html create mode 100644 docs/doxygen/html/bwbuild__sys_8hpp_source.html create mode 100644 docs/doxygen/html/bwcache__api_8hpp_source.html create mode 100644 docs/doxygen/html/bwconf__var_8hpp_source.html create mode 100644 docs/doxygen/html/bwdepends__files_8hpp_source.html create mode 100644 docs/doxygen/html/bwdepends__generator_8hpp_source.html create mode 100644 docs/doxygen/html/bwdepends__integral_8hpp_source.html create mode 100644 docs/doxygen/html/bwgenerator__api_8hpp_source.html create mode 100644 docs/doxygen/html/bwgenerator__integral_8hpp_source.html create mode 100644 docs/doxygen/html/bwgntools_8hpp_source.html create mode 100644 docs/doxygen/html/bwlang_8hpp_source.html create mode 100644 docs/doxygen/html/bwlogger_8hpp_source.html create mode 100644 docs/doxygen/html/bwluatools_8hpp_source.html create mode 100644 docs/doxygen/html/bwmacros__platform_8h_source.html create mode 100644 docs/doxygen/html/bwmodule_8hpp_source.html create mode 100644 docs/doxygen/html/bwpackage_8hpp_source.html create mode 100644 docs/doxygen/html/bwtools_8hpp_source.html create mode 100644 docs/doxygen/html/bwtype_8h_source.html create mode 100644 docs/doxygen/html/classbweas_1_1bwbuilder-members.html create mode 100644 docs/doxygen/html/classbweas_1_1bwbuilder.html create mode 100644 docs/doxygen/html/classbweas_1_1bwbuilder.js create mode 100644 docs/doxygen/html/classbweas_1_1bwdepends__files-members.html create mode 100644 docs/doxygen/html/classbweas_1_1bwdepends__files.html create mode 100644 docs/doxygen/html/classbweas_1_1bwdepends__files.png create mode 100644 docs/doxygen/html/classbweas_1_1bwdepends__generator-members.html create mode 100644 docs/doxygen/html/classbweas_1_1bwdepends__generator.html create mode 100644 docs/doxygen/html/classbweas_1_1bwdepends__generator.png create mode 100644 docs/doxygen/html/classbweas_1_1bwdepends__integral-members.html create mode 100644 docs/doxygen/html/classbweas_1_1bwdepends__integral.html create mode 100644 docs/doxygen/html/classbweas_1_1bwdepends__integral.png create mode 100644 docs/doxygen/html/classbweas_1_1bwlang-members.html create mode 100644 docs/doxygen/html/classbweas_1_1bwlang.html create mode 100644 docs/doxygen/html/classbweas_1_1bwluatools-members.html create mode 100644 docs/doxygen/html/classbweas_1_1bwluatools.html create mode 100644 docs/doxygen/html/classbweas_1_1bwmodule__mg-members.html create mode 100644 docs/doxygen/html/classbweas_1_1bwmodule__mg.html create mode 100644 docs/doxygen/html/classbweas_1_1bwmodule__mg.js create mode 100644 docs/doxygen/html/classbweas_1_1bwpackage-members.html create mode 100644 docs/doxygen/html/classbweas_1_1bwpackage.html create mode 100644 docs/doxygen/html/classbweas_1_1bwpackage.js create mode 100644 docs/doxygen/html/classbweas_1_1bwtools-members.html create mode 100644 docs/doxygen/html/classbweas_1_1bwtools.html create mode 100644 docs/doxygen/html/classbweas_1_1bwtools.js create mode 100644 docs/doxygen/html/classbweas_1_1cache__api_1_1base__bwcache-members.html create mode 100644 docs/doxygen/html/classbweas_1_1cache__api_1_1base__bwcache.html create mode 100644 docs/doxygen/html/classbweas_1_1cache__api_1_1base__bwcache.png create mode 100644 docs/doxygen/html/classbweas_1_1cache__api_1_1fast__bwcache-members.html create mode 100644 docs/doxygen/html/classbweas_1_1cache__api_1_1fast__bwcache.html create mode 100644 docs/doxygen/html/classbweas_1_1cache__api_1_1fast__bwcache.png create mode 100644 docs/doxygen/html/classbweas_1_1cache__api_1_1json__bwcache-members.html create mode 100644 docs/doxygen/html/classbweas_1_1cache__api_1_1json__bwcache.html create mode 100644 docs/doxygen/html/classbweas_1_1cache__api_1_1json__bwcache.png create mode 100644 docs/doxygen/html/classbweas_1_1cache__api_1_1lua__bwcache-members.html create mode 100644 docs/doxygen/html/classbweas_1_1cache__api_1_1lua__bwcache.html create mode 100644 docs/doxygen/html/classbweas_1_1cache__api_1_1lua__bwcache.png create mode 100644 docs/doxygen/html/classbweas_1_1generator__api_1_1base__generator-members.html create mode 100644 docs/doxygen/html/classbweas_1_1generator__api_1_1base__generator.html create mode 100644 docs/doxygen/html/classbweas_1_1generator__api_1_1base__generator.png create mode 100644 docs/doxygen/html/classbweas_1_1generator__api_1_1gninterface_1_1interface__generator-members.html create mode 100644 docs/doxygen/html/classbweas_1_1generator__api_1_1gninterface_1_1interface__generator.html create mode 100644 docs/doxygen/html/classbweas_1_1generator__api_1_1gninterface_1_1interface__generator.png create mode 100644 docs/doxygen/html/classbweas_1_1generator__api_1_1integral__generator-members.html create mode 100644 docs/doxygen/html/classbweas_1_1generator__api_1_1integral__generator.html create mode 100644 docs/doxygen/html/classbweas_1_1generator__api_1_1integral__generator.png create mode 100644 docs/doxygen/html/classbweas_1_1generator__api_1_1lua__generator-members.html create mode 100644 docs/doxygen/html/classbweas_1_1generator__api_1_1lua__generator.html create mode 100644 docs/doxygen/html/classbweas_1_1generator__api_1_1lua__generator.png create mode 100644 docs/doxygen/html/classbweas_1_1generator__tools-members.html create mode 100644 docs/doxygen/html/classbweas_1_1generator__tools.html create mode 100644 docs/doxygen/html/classbweas_1_1integral__generator-members.html create mode 100644 docs/doxygen/html/classbweas_1_1integral__generator.html create mode 100644 docs/doxygen/html/classbweas_1_1log__message-members.html create mode 100644 docs/doxygen/html/classbweas_1_1log__message.html create mode 100644 docs/doxygen/html/classbweas_1_1logger-members.html create mode 100644 docs/doxygen/html/classbweas_1_1logger.html create mode 100644 docs/doxygen/html/classes.html create mode 100644 docs/doxygen/html/clipboard.js create mode 100644 docs/doxygen/html/closed.png create mode 100644 docs/doxygen/html/cookie.js create mode 100644 docs/doxygen/html/dir_68267d1309a1af8e8297ef4c3efbcdba.html create mode 100644 docs/doxygen/html/dir_68267d1309a1af8e8297ef4c3efbcdba.js create mode 100644 docs/doxygen/html/dir_9a2503315d2c62a47b870cbc92f226de.html create mode 100644 docs/doxygen/html/dir_9a2503315d2c62a47b870cbc92f226de.js create mode 100644 docs/doxygen/html/doc.svg create mode 100644 docs/doxygen/html/docd.svg create mode 100644 docs/doxygen/html/doxygen-awesome.css create mode 100644 docs/doxygen/html/doxygen.css create mode 100644 docs/doxygen/html/doxygen.svg create mode 100644 docs/doxygen/html/doxygen_crawl.html create mode 100644 docs/doxygen/html/dynsections.js create mode 100644 docs/doxygen/html/files.html create mode 100644 docs/doxygen/html/files_dup.js create mode 100644 docs/doxygen/html/folderclosed.svg create mode 100644 docs/doxygen/html/folderclosedd.svg create mode 100644 docs/doxygen/html/folderopen.svg create mode 100644 docs/doxygen/html/folderopend.svg create mode 100644 docs/doxygen/html/functions.html create mode 100644 docs/doxygen/html/functions_enum.html create mode 100644 docs/doxygen/html/functions_eval.html create mode 100644 docs/doxygen/html/functions_func.html create mode 100644 docs/doxygen/html/functions_vars.html create mode 100644 docs/doxygen/html/hierarchy.html create mode 100644 docs/doxygen/html/hierarchy.js create mode 100644 docs/doxygen/html/index.html create mode 100644 docs/doxygen/html/jquery.js create mode 100644 docs/doxygen/html/md_README.html create mode 100644 docs/doxygen/html/minus.svg create mode 100644 docs/doxygen/html/minusd.svg create mode 100644 docs/doxygen/html/nav_f.png create mode 100644 docs/doxygen/html/nav_fd.png create mode 100644 docs/doxygen/html/nav_g.png create mode 100644 docs/doxygen/html/nav_h.png create mode 100644 docs/doxygen/html/nav_hd.png create mode 100644 docs/doxygen/html/navtree.css create mode 100644 docs/doxygen/html/navtree.js create mode 100644 docs/doxygen/html/navtreedata.js create mode 100644 docs/doxygen/html/navtreeindex0.js create mode 100644 docs/doxygen/html/open.png create mode 100644 docs/doxygen/html/pages.html create mode 100644 docs/doxygen/html/plus.svg create mode 100644 docs/doxygen/html/plusd.svg create mode 100644 docs/doxygen/html/resize.js create mode 100644 docs/doxygen/html/search/all_0.js create mode 100644 docs/doxygen/html/search/all_1.js create mode 100644 docs/doxygen/html/search/all_2.js create mode 100644 docs/doxygen/html/search/all_3.js create mode 100644 docs/doxygen/html/search/all_4.js create mode 100644 docs/doxygen/html/search/all_5.js create mode 100644 docs/doxygen/html/search/all_6.js create mode 100644 docs/doxygen/html/search/all_7.js create mode 100644 docs/doxygen/html/search/all_8.js create mode 100644 docs/doxygen/html/search/all_9.js create mode 100644 docs/doxygen/html/search/all_a.js create mode 100644 docs/doxygen/html/search/all_b.js create mode 100644 docs/doxygen/html/search/classes_0.js create mode 100644 docs/doxygen/html/search/classes_1.js create mode 100644 docs/doxygen/html/search/classes_2.js create mode 100644 docs/doxygen/html/search/classes_3.js create mode 100644 docs/doxygen/html/search/classes_4.js create mode 100644 docs/doxygen/html/search/classes_5.js create mode 100644 docs/doxygen/html/search/classes_6.js create mode 100644 docs/doxygen/html/search/classes_7.js create mode 100644 docs/doxygen/html/search/classes_8.js create mode 100644 docs/doxygen/html/search/close.svg create mode 100644 docs/doxygen/html/search/enums_0.js create mode 100644 docs/doxygen/html/search/enumvalues_0.js create mode 100644 docs/doxygen/html/search/enumvalues_1.js create mode 100644 docs/doxygen/html/search/enumvalues_2.js create mode 100644 docs/doxygen/html/search/functions_0.js create mode 100644 docs/doxygen/html/search/functions_1.js create mode 100644 docs/doxygen/html/search/functions_2.js create mode 100644 docs/doxygen/html/search/functions_3.js create mode 100644 docs/doxygen/html/search/functions_4.js create mode 100644 docs/doxygen/html/search/functions_5.js create mode 100644 docs/doxygen/html/search/functions_6.js create mode 100644 docs/doxygen/html/search/mag.svg create mode 100644 docs/doxygen/html/search/mag_d.svg create mode 100644 docs/doxygen/html/search/mag_sel.svg create mode 100644 docs/doxygen/html/search/mag_seld.svg create mode 100644 docs/doxygen/html/search/pages_0.js create mode 100644 docs/doxygen/html/search/search.css create mode 100644 docs/doxygen/html/search/search.js create mode 100644 docs/doxygen/html/search/searchdata.js create mode 100644 docs/doxygen/html/search/variables_0.js create mode 100644 docs/doxygen/html/splitbar.png create mode 100644 docs/doxygen/html/splitbard.png create mode 100644 docs/doxygen/html/structbweas_1_1bw__context-members.html create mode 100644 docs/doxygen/html/structbweas_1_1bw__context.html create mode 100644 docs/doxygen/html/structbweas_1_1bwmodule__mg_1_1module-members.html create mode 100644 docs/doxygen/html/structbweas_1_1bwmodule__mg_1_1module.html create mode 100644 docs/doxygen/html/structbweas_1_1bwpackage_1_1config-members.html create mode 100644 docs/doxygen/html/structbweas_1_1bwpackage_1_1config.html create mode 100644 docs/doxygen/html/structbweas_1_1bwpackage_1_1config.js create mode 100644 docs/doxygen/html/structbweas_1_1bwpackage_1_1config_1_1cache__lua-members.html create mode 100644 docs/doxygen/html/structbweas_1_1bwpackage_1_1config_1_1cache__lua.html create mode 100644 docs/doxygen/html/structbweas_1_1bwpackage_1_1config_1_1generator__lua-members.html create mode 100644 docs/doxygen/html/structbweas_1_1bwpackage_1_1config_1_1generator__lua.html create mode 100644 docs/doxygen/html/structbweas_1_1bwpackage_1_1data__bw__package-members.html create mode 100644 docs/doxygen/html/structbweas_1_1bwpackage_1_1data__bw__package.html create mode 100644 docs/doxygen/html/structbweas_1_1bwtools_1_1file-members.html create mode 100644 docs/doxygen/html/structbweas_1_1bwtools_1_1file.html create mode 100644 docs/doxygen/html/structbweas_1_1bwtools_1_1file.js create mode 100644 docs/doxygen/html/structbweas_1_1bwtools_1_1file_1_1mode__file-members.html create mode 100644 docs/doxygen/html/structbweas_1_1bwtools_1_1file_1_1mode__file.html create mode 100644 docs/doxygen/html/structbweas_1_1generator__api_1_1data__transfer-members.html create mode 100644 docs/doxygen/html/structbweas_1_1generator__api_1_1data__transfer.html create mode 100644 docs/doxygen/html/sync_off.png create mode 100644 docs/doxygen/html/sync_on.png create mode 100644 docs/doxygen/html/tab_a.png create mode 100644 docs/doxygen/html/tab_ad.png create mode 100644 docs/doxygen/html/tab_b.png create mode 100644 docs/doxygen/html/tab_bd.png create mode 100644 docs/doxygen/html/tab_h.png create mode 100644 docs/doxygen/html/tab_hd.png create mode 100644 docs/doxygen/html/tab_s.png create mode 100644 docs/doxygen/html/tab_sd.png create mode 100644 docs/doxygen/html/tabs.css create mode 100644 docs/doxygen/latex/Makefile create mode 100644 docs/doxygen/latex/annotated.tex create mode 100644 docs/doxygen/latex/bw__defs_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwbuild__sys_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwcache__api_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwconf__var_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwdepends__files_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwdepends__generator_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwdepends__integral_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwgenerator__api_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwgenerator__integral_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwgntools_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwlang_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwlogger_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwluatools_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwmacros__platform_8h_source.tex create mode 100644 docs/doxygen/latex/bwmodule_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwpackage_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwtools_8hpp_source.tex create mode 100644 docs/doxygen/latex/bwtype_8h_source.tex create mode 100644 docs/doxygen/latex/classbweas_1_1bwbuilder.tex create mode 100644 docs/doxygen/latex/classbweas_1_1bwdepends__files.eps create mode 100644 docs/doxygen/latex/classbweas_1_1bwdepends__files.tex create mode 100644 docs/doxygen/latex/classbweas_1_1bwdepends__generator.eps create mode 100644 docs/doxygen/latex/classbweas_1_1bwdepends__generator.tex create mode 100644 docs/doxygen/latex/classbweas_1_1bwdepends__integral.eps create mode 100644 docs/doxygen/latex/classbweas_1_1bwdepends__integral.tex create mode 100644 docs/doxygen/latex/classbweas_1_1bwlang.tex create mode 100644 docs/doxygen/latex/classbweas_1_1bwluatools.tex create mode 100644 docs/doxygen/latex/classbweas_1_1bwmodule__mg.tex create mode 100644 docs/doxygen/latex/classbweas_1_1bwpackage.tex create mode 100644 docs/doxygen/latex/classbweas_1_1bwtools.tex create mode 100644 docs/doxygen/latex/classbweas_1_1cache__api_1_1base__bwcache.eps create mode 100644 docs/doxygen/latex/classbweas_1_1cache__api_1_1base__bwcache.tex create mode 100644 docs/doxygen/latex/classbweas_1_1cache__api_1_1fast__bwcache.eps create mode 100644 docs/doxygen/latex/classbweas_1_1cache__api_1_1fast__bwcache.tex create mode 100644 docs/doxygen/latex/classbweas_1_1cache__api_1_1json__bwcache.eps create mode 100644 docs/doxygen/latex/classbweas_1_1cache__api_1_1json__bwcache.tex create mode 100644 docs/doxygen/latex/classbweas_1_1cache__api_1_1lua__bwcache.eps create mode 100644 docs/doxygen/latex/classbweas_1_1cache__api_1_1lua__bwcache.tex create mode 100644 docs/doxygen/latex/classbweas_1_1generator__api_1_1base__generator.eps create mode 100644 docs/doxygen/latex/classbweas_1_1generator__api_1_1base__generator.tex create mode 100644 docs/doxygen/latex/classbweas_1_1generator__api_1_1gninterface_1_1interface__generator.eps create mode 100644 docs/doxygen/latex/classbweas_1_1generator__api_1_1gninterface_1_1interface__generator.tex create mode 100644 docs/doxygen/latex/classbweas_1_1generator__api_1_1integral__generator.eps create mode 100644 docs/doxygen/latex/classbweas_1_1generator__api_1_1integral__generator.tex create mode 100644 docs/doxygen/latex/classbweas_1_1generator__api_1_1lua__generator.eps create mode 100644 docs/doxygen/latex/classbweas_1_1generator__api_1_1lua__generator.tex create mode 100644 docs/doxygen/latex/classbweas_1_1generator__tools.tex create mode 100644 docs/doxygen/latex/classbweas_1_1integral__generator.tex create mode 100644 docs/doxygen/latex/classbweas_1_1log__message.tex create mode 100644 docs/doxygen/latex/classbweas_1_1logger.tex create mode 100644 docs/doxygen/latex/doxygen.sty create mode 100644 docs/doxygen/latex/etoc_doxygen.sty create mode 100644 docs/doxygen/latex/files.tex create mode 100644 docs/doxygen/latex/hierarchy.tex create mode 100644 docs/doxygen/latex/longtable_doxygen.sty create mode 100644 docs/doxygen/latex/md_README.tex create mode 100644 docs/doxygen/latex/refman.tex create mode 100644 docs/doxygen/latex/structbweas_1_1bw__context.tex create mode 100644 docs/doxygen/latex/structbweas_1_1bwmodule__mg_1_1module.tex create mode 100644 docs/doxygen/latex/structbweas_1_1bwpackage_1_1config.tex create mode 100644 docs/doxygen/latex/structbweas_1_1bwpackage_1_1config_1_1cache__lua.tex create mode 100644 docs/doxygen/latex/structbweas_1_1bwpackage_1_1config_1_1generator__lua.tex create mode 100644 docs/doxygen/latex/structbweas_1_1bwpackage_1_1data__bw__package.tex create mode 100644 docs/doxygen/latex/structbweas_1_1bwtools_1_1file.tex create mode 100644 docs/doxygen/latex/structbweas_1_1bwtools_1_1file_1_1mode__file.tex create mode 100644 docs/doxygen/latex/structbweas_1_1generator__api_1_1data__transfer.tex create mode 100644 docs/doxygen/latex/tabu_doxygen.sty create mode 100644 src/bs/bwaliases.hpp delete mode 100644 src/bs/bwtype.h create mode 100644 src/bs/tools/bwtemplates.hpp diff --git a/.gitignore b/.gitignore index 0ee8815..7aff442 100644 --- a/.gitignore +++ b/.gitignore @@ -5,9 +5,11 @@ build_linux/ external/LuaJIT/ external/json/ external/lz4/ +dev/doxygen vcpkg_installed/ vcpkg/ +dev/doxygen-awesome.css folder-alias.json result diff --git a/CMakeLists.txt b/CMakeLists.txt index b8eb5b9..bebb905 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ option(USER_BUILD_LUA "Rep LuaJit on external" OFF) option(BWEAS_TEST "Build of bweas test" OFF) set(CMAKE_CXX_STANDARD 17) + set(BWEAS_SLIB slbweas) add_subdirectory(src/) diff --git a/Doxyfile b/Doxyfile new file mode 100644 index 0000000..bb7672f --- /dev/null +++ b/Doxyfile @@ -0,0 +1,2970 @@ +# Doxyfile 1.13.2 + +# This file describes the settings to be used by the documentation system +# Doxygen (www.doxygen.org) for a project. +# +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). +# +# Note: +# +# Use Doxygen to compare the used configuration file with the template +# configuration file: +# doxygen -x [configFile] +# Use Doxygen to compare the used configuration file with the template +# configuration file without replacing the environment variables or CMake type +# replacement variables: +# doxygen -x_noenv [configFile] + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the configuration +# file that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# https://www.gnu.org/software/libiconv/ for the list of possible encodings. +# The default value is: UTF-8. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. + +PROJECT_NAME = "Bweas" + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. + +PROJECT_NUMBER = + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewers a +# quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = + +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. + +PROJECT_LOGO = + +# With the PROJECT_ICON tag one can specify an icon that is included in the tabs +# when the HTML document is shown. Doxygen will copy the logo to the output +# directory. + +PROJECT_ICON = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where Doxygen was started. If +# left blank the current directory will be used. + +OUTPUT_DIRECTORY = docs/doxygen + +# If the CREATE_SUBDIRS tag is set to YES then Doxygen will create up to 4096 +# sub-directories (in 2 levels) under the output directory of each output format +# and will distribute the generated files over these directories. Enabling this +# option can be useful when feeding Doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise cause +# performance problems for the file system. Adapt CREATE_SUBDIRS_LEVEL to +# control the number of sub-directories. +# The default value is: NO. + +CREATE_SUBDIRS = NO + +# Controls the number of sub-directories that will be created when +# CREATE_SUBDIRS tag is set to YES. Level 0 represents 16 directories, and every +# level increment doubles the number of directories, resulting in 4096 +# directories at level 8 which is the default and also the maximum value. The +# sub-directories are organized in 2 levels, the first level always has a fixed +# number of 16 directories. +# Minimum value: 0, maximum value: 8, default value: 8. +# This tag requires that the tag CREATE_SUBDIRS is set to YES. + +CREATE_SUBDIRS_LEVEL = 8 + +# If the ALLOW_UNICODE_NAMES tag is set to YES, Doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by Doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Bulgarian, +# Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch, English +# (United States), Esperanto, Farsi (Persian), Finnish, French, German, Greek, +# Hindi, Hungarian, Indonesian, Italian, Japanese, Japanese-en (Japanese with +# English messages), Korean, Korean-en (Korean with English messages), Latvian, +# Lithuanian, Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, +# Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, +# Swedish, Turkish, Ukrainian and Vietnamese. +# The default value is: English. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES, Doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES, Doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. +# The default value is: YES. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. + +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. +# The default value is: NO. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, Doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. +# The default value is: NO. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES, Doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. + +FULL_PATH_NAMES = YES + +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which Doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where Doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, Doxygen will generate much shorter (but +# less readable) file names. This can be useful if your file system doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen will interpret the +# first line (until the first dot, question mark or exclamation mark) of a +# Javadoc-style comment as the brief description. If set to NO, the Javadoc- +# style will behave just like regular Qt-style comments (thus requiring an +# explicit @brief command for a brief description.) +# The default value is: NO. + +JAVADOC_AUTOBRIEF = NO + +# If the JAVADOC_BANNER tag is set to YES then Doxygen will interpret a line +# such as +# /*************** +# as being the beginning of a Javadoc-style comment "banner". If set to NO, the +# Javadoc-style will behave just like regular comments and it will not be +# interpreted by Doxygen. +# The default value is: NO. + +JAVADOC_BANNER = NO + +# If the QT_AUTOBRIEF tag is set to YES then Doxygen will interpret the first +# line (until the first dot, question mark or exclamation mark) of a Qt-style +# comment as the brief description. If set to NO, the Qt-style will behave just +# like regular Qt-style comments (thus requiring an explicit \brief command for +# a brief description.) +# The default value is: NO. + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. + +MULTILINE_CPP_IS_BRIEF = NO + +# By default Python docstrings are displayed as preformatted text and Doxygen's +# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the +# Doxygen's special commands can be used and the contents of the docstring +# documentation blocks is shown as Doxygen documentation. +# The default value is: YES. + +PYTHON_DOCSTRING = YES + +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES then Doxygen will produce a new +# page for each member. If set to NO, the documentation of a member will be part +# of the file/class/namespace that contains it. +# The default value is: NO. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:^^" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". Note that you cannot put \n's in the value part of an alias +# to insert newlines (in the resulting output). You can put ^^ in the value part +# of an alias to insert a newline as if a physical newline was in the original +# file. When you need a literal { or } or , in the value part of an alias you +# have to escape them by means of a backslash (\), this can lead to conflicts +# with the commands \{ and \} for these it is advised to use the version @{ and +# @} or use a double escape (\\{ and \\}) + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice +# sources only. Doxygen will then generate output that is more tailored for that +# language. For instance, namespaces will be presented as modules, types will be +# separated into more groups, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_SLICE = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by Doxygen: IDL, Java, JavaScript, +# Csharp (C#), C, C++, Lex, D, PHP, md (Markdown), Objective-C, Python, Slice, +# VHDL, Fortran (fixed format Fortran: FortranFixed, free formatted Fortran: +# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser +# tries to guess whether the code is fixed or free formatted code, this is the +# default for Fortran type files). For instance to make Doxygen treat .inc files +# as Fortran files (default is PHP), and .f files as C (default is Fortran), +# use: inc=Fortran f=C. +# +# Note: For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by Doxygen. When specifying no_extension you should add +# * to the FILE_PATTERNS. +# +# Note see also the list of default file extension mappings. + +EXTENSION_MAPPING = + +# If the MARKDOWN_SUPPORT tag is enabled then Doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable +# documentation. See https://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by Doxygen, so you can +# mix Doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. + +MARKDOWN_SUPPORT = YES + +# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up +# to that level are automatically included in the table of contents, even if +# they do not have an id attribute. +# Note: This feature currently applies only to Markdown headings. +# Minimum value: 0, maximum value: 99, default value: 6. +# This tag requires that the tag MARKDOWN_SUPPORT is set to YES. + +TOC_INCLUDE_HEADINGS = 6 + +# The MARKDOWN_ID_STYLE tag can be used to specify the algorithm used to +# generate identifiers for the Markdown headings. Note: Every identifier is +# unique. +# Possible values are: DOXYGEN use a fixed 'autotoc_md' string followed by a +# sequence number starting at 0 and GITHUB use the lower case version of title +# with any whitespace replaced by '-' and punctuation characters removed. +# The default value is: DOXYGEN. +# This tag requires that the tag MARKDOWN_SUPPORT is set to YES. + +MARKDOWN_ID_STYLE = DOXYGEN + +# When enabled Doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. Words listed in the +# AUTOLINK_IGNORE_WORDS tag are excluded from automatic linking. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + +# This tag specifies a list of words that, when matching the start of a word in +# the documentation, will suppress auto links generation, if it is enabled via +# AUTOLINK_SUPPORT. This list does not affect affect links explicitly created +# using \# or the \link or commands. +# This tag requires that the tag AUTOLINK_SUPPORT is set to YES. + +AUTOLINK_IGNORE_WORDS = + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let Doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also makes the inheritance and +# collaboration diagrams that involve STL classes more complete and accurate. +# The default value is: NO. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. +# The default value is: NO. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# https://www.riverbankcomputing.com/software) sources only. Doxygen will parse +# them like normal C++ but will assume all classes use public instead of private +# inheritance when no explicit protection keyword is present. +# The default value is: NO. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# Doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES then Doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. +# The default value is: NO. + +DISTRIBUTE_GROUP_DOC = NO + +# If one adds a struct or class to a group and this option is enabled, then also +# any nested class or struct is added to the same group. By default this option +# is disabled and one has to add nested compounds explicitly via \ingroup. +# The default value is: NO. + +GROUP_NESTED_COMPOUNDS = NO + +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. + +TYPEDEF_HIDES_STRUCT = NO + +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, Doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# Doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run Doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. + +LOOKUP_CACHE_SIZE = 0 + +# The NUM_PROC_THREADS specifies the number of threads Doxygen is allowed to use +# during processing. When set to 0 Doxygen will based this on the number of +# cores available in the system. You can set it explicitly to a value larger +# than 0 to get more control over the balance between CPU load and processing +# speed. At this moment only the input processing can be done using multiple +# threads. Since this is still an experimental feature the default is set to 1, +# which effectively disables parallel processing. Please report any issues you +# encounter. Generating dot graphs in parallel is controlled by the +# DOT_NUM_THREADS setting. +# Minimum value: 0, maximum value: 32, default value: 1. + +NUM_PROC_THREADS = 1 + +# If the TIMESTAMP tag is set different from NO then each generated page will +# contain the date or date and time when the page was generated. Setting this to +# NO can help when comparing the output of multiple runs. +# Possible values are: YES, NO, DATETIME and DATE. +# The default value is: NO. + +TIMESTAMP = NO + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES, Doxygen will assume all entities in +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will +# be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual +# methods of a class will be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIV_VIRTUAL = NO + +# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. + +EXTRACT_PACKAGE = NO + +# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be +# included in the documentation. +# The default value is: NO. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO, +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. If set to YES, local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO, only methods in the interface are +# included. +# The default value is: NO. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. + +EXTRACT_ANON_NSPACES = NO + +# If this flag is set to YES, the name of an unnamed parameter in a declaration +# will be determined by the corresponding definition. By default unnamed +# parameters remain unnamed in the output. +# The default value is: YES. + +RESOLVE_UNNAMED_PARAMS = YES + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO, these classes will be included in the various overviews. This option +# will also hide undocumented C++ concepts if enabled. This option has no effect +# if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_UNDOC_NAMESPACES tag is set to YES, Doxygen will hide all +# undocumented namespaces that are normally visible in the namespace hierarchy. +# If set to NO, these namespaces will be included in the various overviews. This +# option has no effect if EXTRACT_ALL is enabled. +# The default value is: YES. + +HIDE_UNDOC_NAMESPACES = YES + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all friend +# declarations. If set to NO, these declarations will be included in the +# documentation. +# The default value is: NO. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO, these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. + +INTERNAL_DOCS = NO + +# With the correct setting of option CASE_SENSE_NAMES Doxygen will better be +# able to match the capabilities of the underlying filesystem. In case the +# filesystem is case sensitive (i.e. it supports files in the same directory +# whose names only differ in casing), the option must be set to YES to properly +# deal with such files in case they appear in the input. For filesystems that +# are not case sensitive the option should be set to NO to properly deal with +# output files written for symbols that only differ in casing, such as for two +# classes, one named CLASS and the other named Class, and to also support +# references to files without having to specify the exact matching casing. On +# Windows (including Cygwin) and macOS, users should typically set this option +# to NO, whereas on Linux or other Unix flavors it should typically be set to +# YES. +# Possible values are: SYSTEM, NO and YES. +# The default value is: SYSTEM. + +CASE_SENSE_NAMES = SYSTEM + +# If the HIDE_SCOPE_NAMES tag is set to NO then Doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES, the +# scope will be hidden. +# The default value is: NO. + +HIDE_SCOPE_NAMES = NO + +# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then Doxygen will +# append additional text to a page's title, such as Class Reference. If set to +# YES the compound reference will be hidden. +# The default value is: NO. + +HIDE_COMPOUND_REFERENCE= NO + +# If the SHOW_HEADERFILE tag is set to YES then the documentation for a class +# will show which file needs to be included to use the class. +# The default value is: YES. + +SHOW_HEADERFILE = YES + +# If the SHOW_INCLUDE_FILES tag is set to YES then Doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. + +SHOW_INCLUDE_FILES = YES + +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES then Doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. +# The default value is: YES. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then Doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. +# The default value is: NO. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then Doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then Doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and Doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING Doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo +# list. This list is created by putting \todo commands in the documentation. +# The default value is: YES. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test +# list. This list is created by putting \test commands in the documentation. +# The default value is: YES. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if ... \endif and \cond +# ... \endcond blocks. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES, the +# list will mention the files that were used to generate the documentation. +# The default value is: YES. + +SHOW_USED_FILES = YES + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# Doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by Doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by Doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents Doxygen's defaults, run Doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. See also section "Changing the +# layout of pages" for information. +# +# Note that if you run Doxygen from a directory containing a file called +# DoxygenLayout.xml, Doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. See also \cite for info how to create references. + +CITE_BIB_FILES = + +# The EXTERNAL_TOOL_PATH tag can be used to extend the search path (PATH +# environment variable) so that external tools such as latex and gs can be +# found. +# Note: Directories specified with EXTERNAL_TOOL_PATH are added in front of the +# path already specified by the PATH variable, and are added in the order +# specified. +# Note: This option is particularly useful for macOS version 14 (Sonoma) and +# higher, when running Doxygen from Doxywizard, because in this case any user- +# defined changes to the PATH are ignored. A typical example on macOS is to set +# EXTERNAL_TOOL_PATH = /Library/TeX/texbin /usr/local/bin +# together with the standard path, the full search path used by doxygen when +# launching external tools will then become +# PATH=/Library/TeX/texbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin + +EXTERNAL_TOOL_PATH = + +#--------------------------------------------------------------------------- +# Configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by Doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated to standard error (stderr) by Doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. + +WARNINGS = YES + +# If the WARN_IF_UNDOCUMENTED tag is set to YES then Doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. + +WARN_IF_UNDOCUMENTED = YES + +# If the WARN_IF_DOC_ERROR tag is set to YES, Doxygen will generate warnings for +# potential errors in the documentation, such as documenting some parameters in +# a documented function twice, or documenting parameters that don't exist or +# using markup commands wrongly. +# The default value is: YES. + +WARN_IF_DOC_ERROR = YES + +# If WARN_IF_INCOMPLETE_DOC is set to YES, Doxygen will warn about incomplete +# function parameter documentation. If set to NO, Doxygen will accept that some +# parameters have no documentation without warning. +# The default value is: YES. + +WARN_IF_INCOMPLETE_DOC = YES + +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO, Doxygen will only warn about wrong parameter +# documentation, but not about the absence of documentation. If EXTRACT_ALL is +# set to YES then this flag will automatically be disabled. See also +# WARN_IF_INCOMPLETE_DOC +# The default value is: NO. + +WARN_NO_PARAMDOC = NO + +# If WARN_IF_UNDOC_ENUM_VAL option is set to YES, Doxygen will warn about +# undocumented enumeration values. If set to NO, Doxygen will accept +# undocumented enumeration values. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: NO. + +WARN_IF_UNDOC_ENUM_VAL = NO + +# If WARN_LAYOUT_FILE option is set to YES, Doxygen will warn about issues found +# while parsing the user defined layout file, such as missing or wrong elements. +# See also LAYOUT_FILE for details. If set to NO, problems with the layout file +# will be suppressed. +# The default value is: YES. + +WARN_LAYOUT_FILE = YES + +# If the WARN_AS_ERROR tag is set to YES then Doxygen will immediately stop when +# a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS +# then Doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but +# at the end of the Doxygen process Doxygen will return with a non-zero status. +# If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS_PRINT then Doxygen behaves +# like FAIL_ON_WARNINGS but in case no WARN_LOGFILE is defined Doxygen will not +# write the warning messages in between other messages but write them at the end +# of a run, in case a WARN_LOGFILE is defined the warning messages will be +# besides being in the defined file also be shown at the end of a run, unless +# the WARN_LOGFILE is defined as - i.e. standard output (stdout) in that case +# the behavior will remain as with the setting FAIL_ON_WARNINGS. +# Possible values are: NO, YES, FAIL_ON_WARNINGS and FAIL_ON_WARNINGS_PRINT. +# The default value is: NO. + +WARN_AS_ERROR = NO + +# The WARN_FORMAT tag determines the format of the warning messages that Doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# See also: WARN_LINE_FORMAT +# The default value is: $file:$line: $text. + +WARN_FORMAT = "$file:$line: $text" + +# In the $text part of the WARN_FORMAT command it is possible that a reference +# to a more specific place is given. To make it easier to jump to this place +# (outside of Doxygen) the user can define a custom "cut" / "paste" string. +# Example: +# WARN_LINE_FORMAT = "'vi $file +$line'" +# See also: WARN_FORMAT +# The default value is: at line $line of file $file. + +WARN_LINE_FORMAT = "at line $line of file $file" + +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). In case the file specified cannot be opened for writing the +# warning and error messages are written to standard error. When as file - is +# specified the warning and error messages are written to standard output +# (stdout). + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# Configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING +# Note: If this tag is empty the current directory is searched. + +INPUT = src/bs + +# This tag can be used to specify the character encoding of the source files +# that Doxygen parses. Internally Doxygen uses the UTF-8 encoding. Doxygen uses +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: +# https://www.gnu.org/software/libiconv/) for the list of possible encodings. +# See also: INPUT_FILE_ENCODING +# The default value is: UTF-8. + +INPUT_ENCODING = UTF-8 + +# This tag can be used to specify the character encoding of the source files +# that Doxygen parses. The INPUT_FILE_ENCODING tag can be used to specify +# character encoding on a per file pattern basis. Doxygen will compare the file +# name with each pattern and apply the encoding instead of the default +# INPUT_ENCODING if there is a match. The character encodings are a list of the +# form: pattern=encoding (like *.php=ISO-8859-1). +# See also: INPUT_ENCODING for further information on supported encodings. + +INPUT_FILE_ENCODING = + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# read by Doxygen. +# +# Note the list of default checked file patterns might differ from the list of +# default file extension mappings. +# +# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cxxm, +# *.cpp, *.cppm, *.ccm, *.c++, *.c++m, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, +# *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, *.h++, *.ixx, *.l, *.cs, *.d, +# *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, *.md, *.mm, *.dox (to +# be provided as Doxygen C comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, +# *.f18, *.f, *.for, *.vhd, *.vhdl, *.ucf, *.qsf and *.ice. + +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cxxm \ + *.cpp \ + *.cppm \ + *.ccm \ + *.c++ \ + *.c++m \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.idl \ + *.ddl \ + *.odl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.ixx \ + *.l \ + *.cs \ + *.d \ + *.php \ + *.php4 \ + *.php5 \ + *.phtml \ + *.inc \ + *.m \ + *.markdown \ + *.md \ + *.mm \ + *.dox \ + *.py \ + *.pyw \ + *.f90 \ + *.f95 \ + *.f03 \ + *.f08 \ + *.f18 \ + *.f \ + *.for \ + *.vhd \ + *.vhdl \ + *.ucf \ + *.qsf \ + *.ice + +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# +# Note that relative paths are relative to the directory from which Doxygen is +# run. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. +# The default value is: NO. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# ANamespace::AClass, ANamespace::*Test + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. + +EXAMPLE_PATTERNS = * + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that Doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command: +# +# +# +# where is the value of the INPUT_FILTER tag, and is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. +# +# Note that Doxygen will use the data processed and written to standard output +# for further processing, therefore nothing else, like debug statements or used +# commands (so in case of a Windows batch file always use @echo OFF), should be +# written to standard output. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by Doxygen. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by Doxygen. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the Doxygen output. + +USE_MDFILE_AS_MAINPAGE = + +# If the IMPLICIT_DIR_DOCS tag is set to YES, any README.md file found in sub- +# directories of the project's root, is used as the documentation for that sub- +# directory, except when the README.md starts with a \dir, \page or \mainpage +# command. If set to NO, the README.md file needs to start with an explicit \dir +# command in order to be used as directory documentation. +# The default value is: YES. + +IMPLICIT_DIR_DOCS = YES + +# The Fortran standard specifies that for fixed formatted Fortran code all +# characters from position 72 are to be considered as comment. A common +# extension is to allow longer lines before the automatic comment starts. The +# setting FORTRAN_COMMENT_AFTER will also make it possible that longer lines can +# be processed before the automatic comment starts. +# Minimum value: 7, maximum value: 10000, default value: 72. + +FORTRAN_COMMENT_AFTER = 72 + +#--------------------------------------------------------------------------- +# Configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# multi-line macros, enums or list initialized variables directly into the +# documentation. +# The default value is: NO. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct Doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# entity all documented functions referencing it will be listed. +# The default value is: NO. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. + +REFERENCES_LINK_SOURCE = YES + +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of Doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see https://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by Doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set the YES then Doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. + +VERBATIM_HEADERS = YES + +# If the CLANG_ASSISTED_PARSING tag is set to YES then Doxygen will use the +# clang parser (see: +# http://clang.llvm.org/) for more accurate parsing at the cost of reduced +# performance. This can be particularly helpful with template rich C++ code for +# which Doxygen's built-in parser lacks the necessary type information. +# Note: The availability of this option depends on whether or not Doxygen was +# generated with the -Duse_libclang=ON option for CMake. +# The default value is: NO. + +CLANG_ASSISTED_PARSING = NO + +# If the CLANG_ASSISTED_PARSING tag is set to YES and the CLANG_ADD_INC_PATHS +# tag is set to YES then Doxygen will add the directory of each input to the +# include path. +# The default value is: YES. +# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. + +CLANG_ADD_INC_PATHS = YES + +# If clang assisted parsing is enabled you can provide the compiler with command +# line options that you would normally use when invoking the compiler. Note that +# the include paths will already be set by Doxygen for the files and directories +# specified with INPUT and INCLUDE_PATH. +# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. + +CLANG_OPTIONS = + +# If clang assisted parsing is enabled you can provide the clang parser with the +# path to the directory containing a file called compile_commands.json. This +# file is the compilation database (see: +# http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) containing the +# options used when the source files were built. This is equivalent to +# specifying the -p option to a clang tool, such as clang-check. These options +# will then be passed to the parser. Any options specified with CLANG_OPTIONS +# will be added as well. +# Note: The availability of this option depends on whether or not Doxygen was +# generated with the -Duse_libclang=ON option for CMake. + +CLANG_DATABASE_PATH = + +#--------------------------------------------------------------------------- +# Configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. + +ALPHABETICAL_INDEX = YES + +# The IGNORE_PREFIX tag can be used to specify a prefix (or a list of prefixes) +# that should be ignored while generating the index headers. The IGNORE_PREFIX +# tag works for classes, function and member names. The entity will be placed in +# the alphabetical list under the first letter of the entity name that remains +# after removing the prefix. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES, Doxygen will generate HTML output +# The default value is: YES. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank Doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that Doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that Doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of Doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank Doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that Doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank Doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that Doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets +# created by Doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). +# Note: Since the styling of scrollbars can currently not be overruled in +# Webkit/Chromium, the styling will be left out of the default doxygen.css if +# one or more extra stylesheets have been specified. So if scrollbar +# customization is desired it has to be added explicitly. For an example see the +# documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE tag can be used to specify if the generated HTML output +# should be rendered with a dark or light theme. +# Possible values are: LIGHT always generates light mode output, DARK always +# generates dark mode output, AUTO_LIGHT automatically sets the mode according +# to the user preference, uses light mode if no preference is set (the default), +# AUTO_DARK automatically sets the mode according to the user preference, uses +# dark mode if no preference is set and TOGGLE allows a user to switch between +# light and dark mode via a button. +# The default value is: AUTO_LIGHT. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE = AUTO_LIGHT + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the style sheet and background images according to +# this color. Hue is specified as an angle on a color-wheel, see +# https://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use gray-scales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML +# documentation will contain a main index with vertical navigation menus that +# are dynamically created via JavaScript. If disabled, the navigation index will +# consists of multiple levels of tabs that are statically embedded in every HTML +# page. Disable this option to support browsers that do not have JavaScript, +# like the Qt help browser. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_MENUS = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_SECTIONS = NO + +# If the HTML_CODE_FOLDING tag is set to YES then classes and functions can be +# dynamically folded and expanded in the generated HTML source code. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_CODE_FOLDING = YES + +# If the HTML_COPY_CLIPBOARD tag is set to YES then Doxygen will show an icon in +# the top right corner of code and text fragments that allows the user to copy +# its content to the clipboard. Note this only works if supported by the browser +# and the web page is served via a secure context (see: +# https://www.w3.org/TR/secure-contexts/), i.e. using the https: or file: +# protocol. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COPY_CLIPBOARD = YES + +# Doxygen stores a couple of settings persistently in the browser (via e.g. +# cookies). By default these settings apply to all HTML pages generated by +# Doxygen across all projects. The HTML_PROJECT_COOKIE tag can be used to store +# the settings under a project specific key, such that the user preferences will +# be stored separately. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_PROJECT_COOKIE = + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: +# https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To +# create a documentation set, Doxygen will generate a Makefile in the HTML +# output directory. Running make will produce the docset in that directory and +# running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy +# genXcode/_index.html for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_DOCSET = NO + +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# This tag determines the URL of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDURL = + +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES then Doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# on Windows. In the beginning of 2021 Microsoft took the original page, with +# a.o. the download links, offline (the HTML help workshop was already many +# years in maintenance mode). You can download the HTML help workshop from the +# web archives at Installation executable (see: +# http://web.archive.org/web/20160201063255/http://download.microsoft.com/downlo +# ad/0/A/9/0A939EF6-E31C-430F-A3DF-DFAE7960D564/htmlhelp.exe). +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by Doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_HTMLHELP = NO + +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be +# written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_FILE = + +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler (hhc.exe). If non-empty, +# Doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +HHC_LOCATION = + +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the main .chm file (NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +GENERATE_CHI = NO + +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_INDEX_ENCODING = + +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +TOC_EXPAND = NO + +# The SITEMAP_URL tag is used to specify the full URL of the place where the +# generated documentation will be placed on the server by the user during the +# deployment of the documentation. The generated sitemap is called sitemap.xml +# and placed on the directory specified by HTML_OUTPUT. In case no SITEMAP_URL +# is specified no sitemap is generated. For information about the sitemap +# protocol see https://www.sitemaps.org +# This tag requires that the tag GENERATE_HTML is set to YES. + +SITEMAP_URL = + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_VIRTUAL_FOLDER = doc + +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_SECT_FILTER_ATTRS = + +# The QHG_LOCATION tag can be used to specify the location (absolute path +# including file name) of Qt's qhelpgenerator. If non-empty Doxygen will try to +# run qhelpgenerator on the generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +DISABLE_INDEX = YES + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can +# further fine tune the look of the index (see "Fine-tuning the output"). As an +# example, the default style sheet generated by Doxygen has an example that +# shows how to put an image at the root of the tree instead of the PROJECT_NAME. +# Since the tree basically has the same information as the tab index, you could +# consider setting DISABLE_INDEX to YES when enabling this option. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_TREEVIEW = YES + +# When both GENERATE_TREEVIEW and DISABLE_INDEX are set to YES, then the +# FULL_SIDEBAR option determines if the side bar is limited to only the treeview +# area (value NO) or if it should extend to the full height of the window (value +# YES). Setting this to YES gives a layout similar to +# https://docs.readthedocs.io with more room for contents, but less room for the +# project logo, title, and description. If either GENERATE_TREEVIEW or +# DISABLE_INDEX is set to NO, this option has no effect. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FULL_SIDEBAR = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# Doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. + +ENUM_VALUES_PER_LINE = 4 + +# When the SHOW_ENUM_VALUES tag is set doxygen will show the specified +# enumeration values besides the enumeration mnemonics. +# The default value is: NO. + +SHOW_ENUM_VALUES = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. + +TREEVIEW_WIDTH = 250 + +# If the EXT_LINKS_IN_WINDOW option is set to YES, Doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +EXT_LINKS_IN_WINDOW = NO + +# If the OBFUSCATE_EMAILS tag is set to YES, Doxygen will obfuscate email +# addresses. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +OBFUSCATE_EMAILS = YES + +# If the HTML_FORMULA_FORMAT option is set to svg, Doxygen will use the pdf2svg +# tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see +# https://inkscape.org) to generate formulas as SVG images instead of PNGs for +# the HTML output. These images will generally look nicer at scaled resolutions. +# Possible values are: png (the default) and svg (looks nicer but requires the +# pdf2svg or inkscape tool). +# The default value is: png. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FORMULA_FORMAT = png + +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# Doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_FONTSIZE = 10 + +# The FORMULA_MACROFILE can contain LaTeX \newcommand and \renewcommand commands +# to create new LaTeX commands to be used in formulas as building blocks. See +# the section "Including formulas" for details. + +FORMULA_MACROFILE = + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# https://www.mathjax.org) which uses client side JavaScript for the rendering +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +USE_MATHJAX = NO + +# With MATHJAX_VERSION it is possible to specify the MathJax version to be used. +# Note that the different versions of MathJax have different requirements with +# regards to the different settings, so it is possible that also other MathJax +# settings have to be changed when switching between the different MathJax +# versions. +# Possible values are: MathJax_2 and MathJax_3. +# The default value is: MathJax_2. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_VERSION = MathJax_2 + +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. For more details about the output format see MathJax +# version 2 (see: +# http://docs.mathjax.org/en/v2.7-latest/output.html) and MathJax version 3 +# (see: +# http://docs.mathjax.org/en/latest/web/components/output.html). +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility. This is the name for Mathjax version 2, for MathJax version 3 +# this will be translated into chtml), NativeMML (i.e. MathML. Only supported +# for MathJax 2. For MathJax version 3 chtml will be used instead.), chtml (This +# is the name for Mathjax version 3, for MathJax version 2 this will be +# translated into HTML-CSS) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from https://www.mathjax.org before deployment. The default value is: +# - in case of MathJax version 2: https://cdn.jsdelivr.net/npm/mathjax@2 +# - in case of MathJax version 3: https://cdn.jsdelivr.net/npm/mathjax@3 +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_RELPATH = + +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# for MathJax version 2 (see +# https://docs.mathjax.org/en/v2.7-latest/tex.html#tex-and-latex-extensions): +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# For example for MathJax version 3 (see +# http://docs.mathjax.org/en/latest/input/tex/extensions/index.html): +# MATHJAX_EXTENSIONS = ams +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_EXTENSIONS = + +# The MATHJAX_CODEFILE tag can be used to specify a file with JavaScript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: +# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled Doxygen will generate a search box for +# the HTML output. The underlying search engine uses JavaScript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the JavaScript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use + S +# (what the is depends on the OS and browser, but it is typically +# , /