diff --git a/include/compiler/treeifier/ast.hh b/include/compiler/treeifier/ast.hh index 78b53cd..e998f67 100644 --- a/include/compiler/treeifier/ast.hh +++ b/include/compiler/treeifier/ast.hh @@ -1,14 +1,15 @@ #pragma once -#include -#include #include -#include -#include #include +#include +#include +#include +#include + #include "compiler/treeifier/tokenizer.hh" -#include "utils/data.hh" #include "lang/common.hh" +#include "utils/data.hh" using namespace std::string_literals; using namespace ppc; @@ -17,15 +18,15 @@ using namespace ppc::messages; namespace ppc::comp::tree::ast { struct ast_ctx_t; - using parser_func_t = bool (ast_ctx_t &ctx, size_t &res_i, data::map_t &out); - using parser_t = parser_func_t*; + using parser_func_t = bool(ast_ctx_t &ctx, size_t &res_i, data::map_t &out); + using parser_t = parser_func_t *; class group_t { - private: + private: std::map named_parsers; std::set unnamed_parsers; std::map parsers; - public: + public: group_t &replace(const std::string &name, parser_t parser); group_t &add(const std::string &name, parser_t parser); group_t &add(const std::string &name, const lang::namespace_name_t &identifier, parser_t parser); @@ -34,9 +35,9 @@ namespace ppc::comp::tree::ast { }; struct ast_ctx_t { - private: + private: std::unordered_map groups; - public: + public: msg_stack_t &messages; std::vector &tokens; std::set imports; @@ -73,6 +74,28 @@ namespace ppc::comp::tree::ast { data::map_t nmsp_to_map(const loc_namespace_name_t &nmsp); loc_namespace_name_t map_to_nmsp(const data::map_t &map); + } // namespace conv + + class construct_t { + public: + virtual const std::string &name() const = 0; + }; + + class parser_t { + public: + virtual bool parse(ast_ctx_t &ctx, size_t &res_i, construct_t *&out) const = 0; + virtual bool simplify(ast_ctx_t &ctx, size_t &res_i, const construct_t *global, const construct_t *container, const construct_t *current) const = 0; + }; + + namespace constr { + class glob_con_t: public construct_t { + const std::string &name() const { return "$_glob"s; } + bool parse(ast_ctx_t &ctx, size_t &res_i, construct_t *&out) const; + }; + } + + namespace parsers { + } parser_func_t parse_glob, parse_nmsp, parse_identifier, parse_type, parse_exp, parse_stat_exp; diff --git a/src/compiler/treeifier/ast/ast.cc b/src/compiler/treeifier/ast/ast.cc index 34ff378..e875f59 100644 --- a/src/compiler/treeifier/ast/ast.cc +++ b/src/compiler/treeifier/ast/ast.cc @@ -6,16 +6,17 @@ using namespace ppc::lang; using namespace ppc::comp::tree::ast; group_t &ast_ctx_t::group(const std::string &name) { - if (groups.find(name) == groups.end()) return groups[name] = { }; + if (groups.find(name) == groups.end()) return groups[name] = {}; else return groups[name]; } -ast_ctx_t::ast_ctx_t(msg_stack_t &messages, std::vector &tokens): messages(messages), tokens(tokens) { +ast_ctx_t::ast_ctx_t(msg_stack_t &messages, std::vector &tokens): + messages(messages), tokens(tokens) { group("$_exp_val") .add("$_var", parse_exp_var) .add("$_int", parse_exp_int_lit) .add("$_string", parse_exp_str_lit); - // .add_last("$_float", parse_exp_float_lit) + // .add_last("$_float", parse_exp_float_lit) group("$_stat") .add("$_while", { "while" }, parse_while) .add("$_if", { "if" }, parse_if) diff --git a/src/compiler/treeifier/ast/conv.cc b/src/compiler/treeifier/ast/conv.cc index f3a688d..41fd248 100644 --- a/src/compiler/treeifier/ast/conv.cc +++ b/src/compiler/treeifier/ast/conv.cc @@ -1,5 +1,5 @@ -#include #include "compiler/treeifier/ast.hh" +#include namespace ppc::comp::tree::ast::conv { data::map_t identifier_to_map(const located_t &loc) { diff --git a/src/compiler/treeifier/ast/parsers.cc b/src/compiler/treeifier/ast/parsers.cc deleted file mode 100644 index e69de29..0000000 diff --git a/src/compiler/treeifier/ast/parsers/exp.cc b/src/compiler/treeifier/ast/parsers/exp.cc index 700d098..929d85a 100644 --- a/src/compiler/treeifier/ast/parsers/exp.cc +++ b/src/compiler/treeifier/ast/parsers/exp.cc @@ -1,6 +1,6 @@ #include "compiler/treeifier/ast/helper.hh" -#include #include +#include enum precedence_t { NONE, @@ -170,10 +170,7 @@ bool pop_call(size_t n, location_t loc, std::vector> &op_st bool pop_until(const op_data_t &data, tree_helper_t &h, std::vector> &op_stack, array_t &res) { while (!op_stack.empty()) { auto &back_data = op_stack.back(); - if (data.assoc ? - back_data.precedence >= data.precedence : - back_data.precedence > data.precedence - ) break; + if (data.assoc ? back_data.precedence >= data.precedence : back_data.precedence > data.precedence) break; if (!pop(op_stack, res)) return h.err("Expected an expression on the right side of this operator."); } @@ -188,7 +185,9 @@ bool ast::parse_exp_int_lit(ast_ctx_t &ctx, size_t &res_i, map_t &out) { if (h.curr().is_int_literal()) { auto &arr = out["content"].array({}); - for (auto b : h.curr().literal()) arr.push_back((float)b); + for (auto b : h.curr().literal()) { + arr.push_back((float)b); + } out["location"] = conv::loc_to_map(h.loc()); return h.submit(true); } @@ -200,7 +199,9 @@ bool ast::parse_exp_str_lit(ast_ctx_t &ctx, size_t &res_i, map_t &out) { if (h.curr().is_str_literal()) { auto &arr = out["content"].array({}); - for (auto b : h.curr().literal()) arr.push_back((float)b); + for (auto b : h.curr().literal()) { + arr.push_back((float)b); + } out["location"] = conv::loc_to_map(h.loc()); return h.submit(true); } @@ -301,9 +302,8 @@ bool ast::parse_exp(ast_ctx_t &ctx, size_t &res_i, map_t &out) { }; h.force_parse(parse_identifier, "Expected an identifier.", member_access["name"].map({})); member_access["location"] = conv::loc_to_map( - conv::map_to_loc(member_access["name"].map()["location"].string()).intersect( - conv::map_to_loc(res.back().map()["location"].string()) - ) + conv::map_to_loc(member_access["name"].map()["location"].string()) + .intersect(conv::map_to_loc(res.back().map()["location"].string())) ); res.pop_back(); res.push_back(member_access); diff --git a/src/compiler/treeifier/ast/parsers/glob.cc b/src/compiler/treeifier/ast/parsers/glob.cc index 2b8021a..a28053f 100644 --- a/src/compiler/treeifier/ast/parsers/glob.cc +++ b/src/compiler/treeifier/ast/parsers/glob.cc @@ -1,6 +1,5 @@ #include "compiler/treeifier/ast.hh" #include "compiler/treeifier/ast/helper.hh" -// #include "./type.cc" using namespace ppc::comp::tree::ast; diff --git a/src/compiler/treeifier/lexer.cc b/src/compiler/treeifier/lexer.cc index 0127d64..b12b3b9 100644 --- a/src/compiler/treeifier/lexer.cc +++ b/src/compiler/treeifier/lexer.cc @@ -1,6 +1,6 @@ -#include #include "compiler/treeifier/lexer.hh" #include "utils/message.hh" +#include using namespace ppc; using namespace ppc::messages; @@ -73,7 +73,7 @@ static res_t lexlet_oct(char c, std::vector &tok) { if (isoct(c)) return lexer_none(); else if (isdigit(c)) throw message_t::error("An octal literal may only contain octal digits."); else return lexer_end(token_t::OCT_LITERAL); -}; +}; static res_t lexlet_float(char c, std::vector &tok) { if (isdigit(c)) return lexer_none(); else return lexer_end(token_t::FLOAT_LITERAL); @@ -193,7 +193,7 @@ std::vector token_t::parse_many(ppc::messages::msg_stack_t &msg_stack, } } } - catch (const messages::message_t &msg) { + catch (const messages::message_t &msg) { throw message_t(msg.level, msg.content, location_t(filename, line, start, i - curr_token.size(), curr_token.size())); } } @@ -214,7 +214,8 @@ std::vector token_t::parse_file(ppc::messages::msg_stack_t &msg_stack, std::vector contents; int c; - while ((c = f.get()) != EOF) contents.push_back(c); + while ((c = f.get()) != EOF) + contents.push_back(c); return parse_many(msg_stack, filename, std::string { contents.begin(), contents.end() }); } diff --git a/src/compiler/treeifier/operators.cc b/src/compiler/treeifier/operators.cc index b03bd90..584c264 100644 --- a/src/compiler/treeifier/operators.cc +++ b/src/compiler/treeifier/operators.cc @@ -1,5 +1,5 @@ -#include #include "compiler/treeifier/tokenizer.hh" +#include using namespace ppc::comp::tree; using namespace ppc::comp; diff --git a/src/compiler/treeifier/tokenizer.cc b/src/compiler/treeifier/tokenizer.cc index e603d86..2da0e7d 100644 --- a/src/compiler/treeifier/tokenizer.cc +++ b/src/compiler/treeifier/tokenizer.cc @@ -1,7 +1,7 @@ -#include -#include -#include "compiler/treeifier/tokenizer.hh" #include "compiler/treeifier/lexer.hh" +#include "compiler/treeifier/tokenizer.hh" +#include +#include using namespace ppc; using namespace messages; diff --git a/src/lang/common.cc b/src/lang/common.cc index bf4bd70..7c5a004 100644 --- a/src/lang/common.cc +++ b/src/lang/common.cc @@ -1,6 +1,5 @@ - -#include #include "lang/common.hh" +#include namespace ppc::lang { std::string loc_namespace_name_t::to_string() const { @@ -57,4 +56,3 @@ namespace ppc::lang { return res; } } - diff --git a/src/lang/module.cc b/src/lang/module.cc index b14c4b1..1b91993 100644 --- a/src/lang/module.cc +++ b/src/lang/module.cc @@ -32,9 +32,15 @@ definition_t::definition_t(const definition_t &val) { definition_t::~definition_t() { switch (this->kind) { - case FUNCTION: delete this->val.func; break; - case FIELD: delete this->val.field; break; - case STRUCT: delete this->val.str; break; + case FUNCTION: + delete this->val.func; + break; + case FIELD: + delete this->val.field; + break; + case STRUCT: + delete this->val.str; + break; } } @@ -53,12 +59,11 @@ field_t &definition_t::get_field() { } - statement_t statement_t::call(const namespace_name_t &func) { - return { CALL, { .call = new auto(func) }}; + return { CALL, { .call = new auto(func) } }; } statement_t statement_t::stack(int64_t stack) { - return { STACK, { .stack = stack }}; + return { STACK, { .stack = stack } }; } statement_t statement_t::ret() { return { RETURN }; diff --git a/src/lsproj.cc b/src/lsproj.cc index d32fe3e..f1d3dc7 100644 --- a/src/lsproj.cc +++ b/src/lsproj.cc @@ -1,6 +1,9 @@ -#include #include #include +#include +#include + +using namespace std::string_literals; struct project_t { std::string output; @@ -8,7 +11,7 @@ struct project_t { }; std::string read_str(std::istream &f, const std::string &skip_chars, const std::string &end_chars, int &end_char) { - std::vector res { }; + std::vector res {}; int c; while (true) { @@ -49,10 +52,10 @@ project_t read_project(std::istream &f) { int end_ch; std::string name = read_str(f, " \v\t\r\n", "\n", end_ch); std::size_t cap = 16, n = 0; - std::vector deps { }; + std::vector deps {}; if (name.length() == 0) { - throw (std::string)"The name of a project may not be empty."; + throw "The name of a project may not be empty."s; } if (end_ch == -1) { @@ -63,14 +66,14 @@ project_t read_project(std::istream &f) { } if (name.find(',') != std::string::npos || name.find(' ') != std::string::npos) { - throw (std::string)"The name of a project may not contain spaces or commas."; + throw "The name of a project may not contain spaces or commas."s; } while (true) { std::string dep = read_str(f, " \v\t\r\n", ",\n", end_ch); if (dep.find(' ') != std::string::npos) { - throw (std::string)"The name of a dependency may not contain spaces."; + throw "The name of a dependency may not contain spaces."s; } if (dep.length()) { @@ -90,38 +93,38 @@ void print_err(const std::string &error, const std::string &context) { std::cerr << context << ": " << error; } -int main(int argc, const char* argv[]) { +int main(int argc, const char *argv[]) { std::string proj_name = ""; try { argc--; argv++; if (argc != 3) { - throw (std::string)"Incorrect usage. Syntax: [src-dir] [project-name] [output|deps]."; + throw "Incorrect usage. Syntax: [src-dir] [project-name] [output|deps]."s; } - std::string proj_path = (std::string)argv[0] + "/" + argv[1] + ".proj"; + std::string proj_path = (std::string) argv[0] + "/" + argv[1] + ".proj"; proj_name = argv[1]; std::ifstream f { proj_path, std::ios_base::in }; if (!f.is_open()) { - throw (std::string)"The project '" + argv[1] +"' doesn't exist."; + throw "The project '"s + argv[1] + "' doesn't exist."s; } project_t project = read_project(f); f.close(); - if ((std::string)argv[2] == "output") { + if ((std::string) argv[2] == "output") { std::cout << project.output; } - else if ((std::string)argv[2] == "deps") { + else if ((std::string) argv[2] == "deps") { for (std::string dep : project.deps) { std::cout << dep << " "; } } else { - throw (std::string)"Invalid command given. Available commands: output, deps."; + throw "Invalid command given. Available commands: output, deps."s; } std::cout << std::endl; diff --git a/src/main/main.cc b/src/main/main.cc index 5a9a16b..6e9a029 100644 --- a/src/main/main.cc +++ b/src/main/main.cc @@ -8,25 +8,25 @@ #define DISABLE_NEWLINE_AUTO_RETURN 0x8 #endif -#include #include +#include #undef ERROR #undef INFO #endif -#include -#include -#include -#include -#include "utils/threading.hh" -#include "utils/strings.hh" -#include "utils/json.hh" +#include "./opions.hh" +#include "compiler/treeifier/ast.hh" #include "compiler/treeifier/lexer.hh" #include "compiler/treeifier/tokenizer.hh" -#include "compiler/treeifier/ast.hh" -#include "./opions.hh" +#include "utils/json.hh" +#include "utils/strings.hh" +#include "utils/threading.hh" +#include +#include +#include +#include using std::cout; using std::size_t; @@ -35,79 +35,79 @@ using namespace ppc::comp::tree; using namespace ppc::comp::tree::ast; void add_flags(options::parser_t &parser) { - parser.add_flag({ - .name = "version", - .shorthands = "v", - .description = "Displays version and license agreement of this binary", - .execute = [](options::parser_t &parser, const std::string &option, ppc::messages::msg_stack_t &global_stack) { - cout << "++C compiler\n" - << " Version: v" << PPC_VERSION_MAJOR << '.' << PPC_VERSION_MINOR << '.' << PPC_VERSION_BUILD - #if WINDOWS - << " (Windows)" - #elif LINUX + parser.add_flag({ .name = "version", + .shorthands = "v", + .description = "Displays version and license agreement of this binary", + .execute = [](options::parser_t &parser, const std::string &option, ppc::messages::msg_stack_t &global_stack) { + cout << "++C compiler\n" + << " Version: v" << PPC_VERSION_MAJOR << '.' << PPC_VERSION_MINOR << '.' << PPC_VERSION_BUILD +#if WINDOWS + << " (Windows)" +#elif LINUX << " (Linux)" - #endif - << "\n" - << " License: MIT Copyright (C) TopchetoEU\n"; - exit(0); - } - }); - parser.add_flag({ - .name = "help", - .shorthands = "h", - .description = "Displays a list of all flags and their meaning", - .execute = [](options::parser_t &parser, const std::string &option, ppc::messages::msg_stack_t &global_stack) { - cout << "Usage: ...flags ...files\n\n" - << "Flags and file names can be interlaced\n" - << "Flags will execute in the order they're written, then compilation begins\n\n" - << "Flags:\n"; +#endif + << "\n" + << " License: MIT Copyright (C) TopchetoEU\n"; + exit(0); + } }); + parser.add_flag({ .name = "help", + .shorthands = "h", + .description = "Displays a list of all flags and their meaning", + .execute = [](options::parser_t &parser, const std::string &option, ppc::messages::msg_stack_t &global_stack) { + cout << "Usage: ...flags ...files\n\n" + << "Flags and file names can be interlaced\n" + << "Flags will execute in the order they're written, then compilation begins\n\n" + << "Flags:\n"; - for (const auto &flag : parser) { - std::stringstream buff; - buff << " --" << flag.name; + for (const auto &flag : parser) { + std::stringstream buff; + buff << " --" << flag.name; - if (flag.match_type) buff << "=..."; - if (flag.shorthands.size()) { - buff << " ("; - bool first = true; - for (char shorthand : flag.shorthands) { - if (!first) buff << ","; - else first = false; + if (flag.match_type) buff << "=..."; + if (flag.shorthands.size()) { + buff << " ("; + bool first = true; + for (char shorthand : flag.shorthands) { + if (!first) buff << ","; + else first = false; - buff << " -"; - buff << std::string { shorthand }; - } - buff << ")"; - } + buff << " -"; + buff << std::string { shorthand }; + } + buff << ")"; + } - buff << " "; + buff << " "; - cout << buff.str(); - size_t n = buff.str().length(); + cout << buff.str(); + size_t n = buff.str().length(); - if (flag.description.size()) { - const size_t padding = 24; - const size_t msg_width = 80 - padding; + if (flag.description.size()) { + const size_t padding = 24; + const size_t msg_width = 80 - padding; - for (size_t i = 0; i < padding - n; i++) cout << ' '; + for (size_t i = 0; i < padding - n; i++) + cout << ' '; - int len = flag.description.length(); + int len = flag.description.length(); - for (size_t i = 0; i < len / msg_width; i++) { - for (size_t j = 0; j < msg_width; j++) cout << flag.description[i * msg_width + j]; - cout << std::endl; - for (size_t j = 0; j < padding; j++) cout << ' '; - } + for (size_t i = 0; i < len / msg_width; i++) { + for (size_t j = 0; j < msg_width; j++) + cout << flag.description[i * msg_width + j]; + cout << std::endl; + for (size_t j = 0; j < padding; j++) + cout << ' '; + } - int remainder = len % msg_width; + int remainder = len % msg_width; - for (int i = 0; i < remainder; i++) cout << flag.description[len - remainder + i]; - } + for (int i = 0; i < remainder; i++) + cout << flag.description[len - remainder + i]; + } - printf("\n"); - } - } - }); + printf("\n"); + } + } }); parser.add_flag({ .name = "silent", .shorthands = "qs", @@ -118,27 +118,25 @@ void add_flags(options::parser_t &parser) { .description = "Sets a lower limit of messages that will print. Accepted values: 'all', 'debug', 'suggestion', 'info', 'warning', 'error', 'none'", .match_type = options::MATCH_PREFIX, }); - parser.add_flag({ - .name = "print-what", - .description = "Prints a 'what?' type of message (you'll see)", - .match_type = options::MATCH_PREFIX, - .execute = [](options::parser_t &parser, const std::string &option, ppc::messages::msg_stack_t &global_stack) { - global_stack.push(messages::message_t((messages::message_t::level_t)69, "IDK LOL.")); - } - }); + parser.add_flag({ .name = "print-what", + .description = "Prints a 'what?' type of message (you'll see)", + .match_type = options::MATCH_PREFIX, + .execute = [](options::parser_t &parser, const std::string &option, ppc::messages::msg_stack_t &global_stack) { + global_stack.push(messages::message_t((messages::message_t::level_t)69, "IDK LOL.")); + } }); } int main(int argc, const char *argv[]) { - #ifdef WINDOWS +#ifdef WINDOWS HANDLE handleOut = GetStdHandle(STD_OUTPUT_HANDLE); DWORD consoleMode; GetConsoleMode(handleOut, &consoleMode); consoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; consoleMode |= DISABLE_NEWLINE_AUTO_RETURN; SetConsoleMode(handleOut, consoleMode); - #endif +#endif - std::vector args{ argv + 1, argv + argc }; + std::vector args { argv + 1, argv + argc }; std::vector files; messages::msg_stack_t msg_stack; @@ -170,7 +168,7 @@ int main(int argc, const char *argv[]) { catch (const messages::message_t &msg) { msg_stack.push(msg); } - #ifndef PROFILE_debug +#ifndef PROFILE_debug catch (const std::string &msg) { msg_stack.push(message_t::error(msg)); } @@ -178,7 +176,7 @@ int main(int argc, const char *argv[]) { std::cout << std::endl; msg_stack.push(message_t::error("A fatal error occurred.")); } - #endif +#endif msg_stack.print(std::cout, messages::message_t::DEBUG, true); diff --git a/src/main/opions.hh b/src/main/opions.hh index f91f100..22ae0f4 100644 --- a/src/main/opions.hh +++ b/src/main/opions.hh @@ -1,8 +1,8 @@ #pragma once -#include -#include "utils/message.hh" #include "utils/data.hh" +#include "utils/message.hh" +#include namespace ppc::options { enum flag_match_type_t { @@ -21,9 +21,9 @@ namespace ppc::options { }; struct parser_t { - private: + private: std::vector flags; - public: + public: void add_flag(const flag_t &flag); void clear_flags(); diff --git a/src/main/options.cc b/src/main/options.cc index 9328a1c..f8d655b 100644 --- a/src/main/options.cc +++ b/src/main/options.cc @@ -1,5 +1,5 @@ -#include #include "./opions.hh" +#include using namespace ppc; diff --git a/src/utils/data.cc b/src/utils/data.cc index 39bddb7..d86e213 100644 --- a/src/utils/data.cc +++ b/src/utils/data.cc @@ -1,4 +1,7 @@ #include "utils/data.hh" +#include + +using namespace std::string_literals; namespace ppc::data { bool value_t::is_null() const { @@ -44,45 +47,45 @@ namespace ppc::data { array_t &value_t::array() { if (is_array()) return *val.arr; - else throw (std::string)"The value isn't an array."; + else throw "The value isn't an array."s; } map_t &value_t::map() { if (is_map()) return *val.map; - else throw (std::string)"The value isn't a map."; + else throw "The value isn't a map."s; } number_t &value_t::number() { if (is_number()) return val.num; - else throw (std::string)"The value isn't a number."; + else throw "The value isn't a number."s; } string_t &value_t::string() { if (is_string()) return *val.str; - else throw (std::string)"The value isn't a string."; + else throw "The value isn't a string."s; } bool_t &value_t::boolean() { if (is_bool()) return val.bl; - else throw (std::string)"The value isn't a bool."; + else throw "The value isn't a bool."s; } const array_t &value_t::array() const { if (is_array()) return *val.arr; - else throw (std::string)"The value isn't an array."; + else throw "The value isn't an array."s; } const map_t &value_t::map() const { if (is_map()) return *val.map; - else throw (std::string)"The value isn't a map."; + else throw "The value isn't a map."s; } number_t value_t::number() const { if (is_number()) return val.num; - else throw (std::string)"The value isn't a number."; + else throw "The value isn't a number."s; } const string_t &value_t::string() const { if (is_string()) return *val.str; - else throw (std::string)"The value isn't a string."; + else throw "The value isn't a string."s; } bool_t value_t::boolean() const { if (is_bool()) return val.bl; - else throw (std::string)"The value isn't a bool."; + else throw "The value isn't a bool."s; } value_t::value_t() { diff --git a/src/utils/location.cc b/src/utils/location.cc index 9169ddd..03cfecf 100644 --- a/src/utils/location.cc +++ b/src/utils/location.cc @@ -39,7 +39,7 @@ location_t location_t::intersect(location_t other) const { location_t a = *this; location_t b = other; - if (a.start == -1u || b.start == -1u) return { }; + if (a.start == -1u || b.start == -1u) return {}; if (a.start > b.start) return other.intersect(*this); @@ -67,7 +67,6 @@ bool location_t::operator==(const location_t &other) const { } - std::string empty = ""; location_t::location_t(): @@ -84,11 +83,12 @@ location_t::location_t(const std::string &filename, std::size_t line, std::size_ location_t(filename, line, start, code_start, -1) { } location_t::location_t(std::size_t line, std::size_t start, std::size_t code_start, std::size_t length): location_t(empty, line, start, code_start, length) { } -location_t::location_t(const std::string &filename, std::size_t line, std::size_t start, std::size_t code_start, std::size_t length): filename(filename) { +location_t::location_t(const std::string &filename, std::size_t line, std::size_t start, std::size_t code_start, std::size_t length): + filename(filename) { this->length = length; this->code_start = code_start; this->line = line; this->start = start; } -const location_t location_t::NONE = { }; +const location_t location_t::NONE = {}; diff --git a/src/utils/message.cc b/src/utils/message.cc index 61959ea..a65754c 100644 --- a/src/utils/message.cc +++ b/src/utils/message.cc @@ -1,6 +1,6 @@ +#include "utils/message.hh" #include #include -#include "utils/message.hh" using namespace ppc; @@ -10,15 +10,27 @@ namespace ppc::messages { std::string level_readable; switch (level) { - case message_t::DEBUG: level_readable = "debug"; break; - case message_t::SUGGESTION: level_readable = "suggestion"; break; - case message_t::INFO: level_readable = "info"; break; - case message_t::WARNING: level_readable = "warning"; break; - case message_t::ERROR: level_readable = "error"; break; - default: level_readable = "what?"; break; + case message_t::DEBUG: + level_readable = "debug"; + break; + case message_t::SUGGESTION: + level_readable = "suggestion"; + break; + case message_t::INFO: + level_readable = "info"; + break; + case message_t::WARNING: + level_readable = "warning"; + break; + case message_t::ERROR: + level_readable = "error"; + break; + default: + level_readable = "what?"; + break; } - std::stringstream res { }; + std::stringstream res {}; if (loc_readable.length()) res << loc_readable << ": "; res << level_readable << ": " << content; @@ -42,7 +54,7 @@ namespace ppc::messages { if (msg.level < threshold) continue; std::string loc_readable = msg.location.to_string(); - + switch (msg.level) { case message_t::DEBUG: output << (color_output ? "\e[38;5;8mdebug: " : "debug: "); @@ -51,7 +63,7 @@ namespace ppc::messages { output << (color_output ? "\e[38;5;45msuggestion: " : "suggestion: "); break; case message_t::INFO: - output << (color_output ? "\e[38;5;33minfo: ": "info: "); + output << (color_output ? "\e[38;5;33minfo: " : "info: "); break; case message_t::WARNING: output << (color_output ? "\e[38;5;214mwarning: " : "warning: "); diff --git a/src/utils/strings.cc b/src/utils/strings.cc index 1482a81..44ce163 100644 --- a/src/utils/strings.cc +++ b/src/utils/strings.cc @@ -1,5 +1,5 @@ -#include #include "utils/strings.hh" +#include using namespace ppc; @@ -11,10 +11,10 @@ std::vector str::split(const std::string &splittable, std::initiali if (std::string { splitters }.find(c) == std::string::npos) { buff << c; } - else { + else { if (!buff.str().empty() || !remove_empty_entries) { res.push_back(buff.str()); - buff = { }; + buff = {}; } } } diff --git a/src/utils/threading.cc b/src/utils/threading.cc index 04ea928..281aef3 100644 --- a/src/utils/threading.cc +++ b/src/utils/threading.cc @@ -10,7 +10,7 @@ using namespace std::string_literals; threading::thread_t threading::thread_t::start_impl(void *func, void *args) { DWORD id; - HANDLE hnd = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, args, 0, &id); + HANDLE hnd = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) func, args, 0, &id); if (!hnd) throw "Couldn't create thread."s; return { hnd }; @@ -31,14 +31,14 @@ threading::thread_t::~thread_t() { threading::thread_t threading::thread_t::start_impl(void *func, void *args) { pthread_t *handle = new pthread_t; - pthread_create(handle, nullptr, (void* (*)(void *))func, args); + pthread_create(handle, nullptr, (void *(*) (void *) ) func, args); return { handle }; } int threading::thread_t::join() const { - return pthread_join(*(pthread_t*)handle, nullptr); + return pthread_join(*(pthread_t *) handle, nullptr); } threading::thread_t::~thread_t() { - delete (pthread_t*)handle; + delete (pthread_t *) handle; } #endif \ No newline at end of file