AST reprogramming #5

Open
TopchetoEU wants to merge 15 commits from TopchetoEU/ast-reporgramming into master
20 changed files with 218 additions and 175 deletions
Showing only changes of commit b8594aecd6 - Show all commits

View File

@ -1,14 +1,15 @@
#pragma once
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#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<lang::namespace_name_t, std::string> named_parsers;
std::set<std::string> unnamed_parsers;
std::map<std::string, parser_t> 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<std::string, group_t> groups;
public:
public:
msg_stack_t &messages;
std::vector<token_t> &tokens;
std::set<loc_namespace_name_t> 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;

View File

@ -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<token_t> &tokens): messages(messages), tokens(tokens) {
ast_ctx_t::ast_ctx_t(msg_stack_t &messages, std::vector<token_t> &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)

View File

@ -1,5 +1,5 @@
#include <sstream>
#include "compiler/treeifier/ast.hh"
#include <sstream>
namespace ppc::comp::tree::ast::conv {
data::map_t identifier_to_map(const located_t<std::string> &loc) {

View File

@ -1,6 +1,6 @@
#include "compiler/treeifier/ast/helper.hh"
#include <map>
#include <algorithm>
#include <map>
enum precedence_t {
NONE,
@ -170,10 +170,7 @@ bool pop_call(size_t n, location_t loc, std::vector<located_t<op_data_t>> &op_st
bool pop_until(const op_data_t &data, tree_helper_t &h, std::vector<located_t<op_data_t>> &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);

View File

@ -1,6 +1,5 @@
#include "compiler/treeifier/ast.hh"
#include "compiler/treeifier/ast/helper.hh"
// #include "./type.cc"
using namespace ppc::comp::tree::ast;

View File

@ -1,6 +1,6 @@
#include <sstream>
#include "compiler/treeifier/lexer.hh"
#include "utils/message.hh"
#include <sstream>
using namespace ppc;
using namespace ppc::messages;
@ -73,7 +73,7 @@ static res_t lexlet_oct(char c, std::vector<char> &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<char> &tok) {
if (isdigit(c)) return lexer_none();
else return lexer_end(token_t::FLOAT_LITERAL);
@ -193,7 +193,7 @@ std::vector<token_t> 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> token_t::parse_file(ppc::messages::msg_stack_t &msg_stack,
std::vector<char> 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() });
}

View File

@ -1,5 +1,5 @@
#include <string>
#include "compiler/treeifier/tokenizer.hh"
#include <string>
using namespace ppc::comp::tree;
using namespace ppc::comp;

View File

@ -1,7 +1,7 @@
#include <string>
#include <algorithm>
#include "compiler/treeifier/tokenizer.hh"
#include "compiler/treeifier/lexer.hh"
#include "compiler/treeifier/tokenizer.hh"
#include <algorithm>
#include <string>
using namespace ppc;
using namespace messages;

View File

@ -1,6 +1,5 @@
#include <sstream>
#include "lang/common.hh"
#include <sstream>
namespace ppc::lang {
std::string loc_namespace_name_t::to_string() const {
@ -57,4 +56,3 @@ namespace ppc::lang {
return res;
}
}

View File

@ -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 };

View File

@ -1,6 +1,9 @@
#include <vector>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
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<char> res { };
std::vector<char> 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<std::string> deps { };
std::vector<std::string> 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;

View File

@ -8,25 +8,25 @@
#define DISABLE_NEWLINE_AUTO_RETURN 0x8
#endif
#include <windows.h>
#include <conio.h>
#include <windows.h>
#undef ERROR
#undef INFO
#endif
#include <sstream>
#include <fstream>
#include <iostream>
#include <cstdio>
#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 <cstdio>
#include <fstream>
#include <iostream>
#include <sstream>
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<std::string> args{ argv + 1, argv + argc };
std::vector<std::string> args { argv + 1, argv + argc };
std::vector<std::string> 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);

View File

@ -1,8 +1,8 @@
#pragma once
#include <vector>
#include "utils/message.hh"
#include "utils/data.hh"
#include "utils/message.hh"
#include <vector>
namespace ppc::options {
enum flag_match_type_t {
@ -21,9 +21,9 @@ namespace ppc::options {
};
struct parser_t {
private:
private:
std::vector<flag_t> flags;
public:
public:
void add_flag(const flag_t &flag);
void clear_flags();

View File

@ -1,5 +1,5 @@
#include <set>
#include "./opions.hh"
#include <set>
using namespace ppc;

View File

@ -1,4 +1,7 @@
#include "utils/data.hh"
#include <string>
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() {

View File

@ -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 = {};

View File

@ -1,6 +1,6 @@
#include "utils/message.hh"
#include <iostream>
#include <sstream>
#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: ");

View File

@ -1,5 +1,5 @@
#include <sstream>
#include "utils/strings.hh"
#include <sstream>
using namespace ppc;
@ -11,10 +11,10 @@ std::vector<std::string> 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 = {};
}
}
}

View File

@ -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