refactor: fix formatting

This commit is contained in:
TopchetoEU 2023-01-20 16:43:52 +02:00
parent 8f361edb5d
commit b8594aecd6
No known key found for this signature in database
GPG Key ID: 5ED5FFB2A3F5DB21
20 changed files with 218 additions and 175 deletions

View File

@ -1,14 +1,15 @@
#pragma once #pragma once
#include <string>
#include <set>
#include <map> #include <map>
#include <unordered_set>
#include <unordered_map>
#include <memory> #include <memory>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include "compiler/treeifier/tokenizer.hh" #include "compiler/treeifier/tokenizer.hh"
#include "utils/data.hh"
#include "lang/common.hh" #include "lang/common.hh"
#include "utils/data.hh"
using namespace std::string_literals; using namespace std::string_literals;
using namespace ppc; using namespace ppc;
@ -17,15 +18,15 @@ using namespace ppc::messages;
namespace ppc::comp::tree::ast { namespace ppc::comp::tree::ast {
struct ast_ctx_t; struct ast_ctx_t;
using parser_func_t = bool (ast_ctx_t &ctx, size_t &res_i, data::map_t &out); 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_t = parser_func_t *;
class group_t { class group_t {
private: private:
std::map<lang::namespace_name_t, std::string> named_parsers; std::map<lang::namespace_name_t, std::string> named_parsers;
std::set<std::string> unnamed_parsers; std::set<std::string> unnamed_parsers;
std::map<std::string, parser_t> parsers; std::map<std::string, parser_t> parsers;
public: public:
group_t &replace(const std::string &name, parser_t parser); 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, parser_t parser);
group_t &add(const std::string &name, const lang::namespace_name_t &identifier, 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 { struct ast_ctx_t {
private: private:
std::unordered_map<std::string, group_t> groups; std::unordered_map<std::string, group_t> groups;
public: public:
msg_stack_t &messages; msg_stack_t &messages;
std::vector<token_t> &tokens; std::vector<token_t> &tokens;
std::set<loc_namespace_name_t> imports; 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); data::map_t nmsp_to_map(const loc_namespace_name_t &nmsp);
loc_namespace_name_t map_to_nmsp(const data::map_t &map); 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; 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; using namespace ppc::comp::tree::ast;
group_t &ast_ctx_t::group(const std::string &name) { 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]; 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") group("$_exp_val")
.add("$_var", parse_exp_var) .add("$_var", parse_exp_var)
.add("$_int", parse_exp_int_lit) .add("$_int", parse_exp_int_lit)
.add("$_string", parse_exp_str_lit); .add("$_string", parse_exp_str_lit);
// .add_last("$_float", parse_exp_float_lit) // .add_last("$_float", parse_exp_float_lit)
group("$_stat") group("$_stat")
.add("$_while", { "while" }, parse_while) .add("$_while", { "while" }, parse_while)
.add("$_if", { "if" }, parse_if) .add("$_if", { "if" }, parse_if)

View File

@ -1,5 +1,5 @@
#include <sstream>
#include "compiler/treeifier/ast.hh" #include "compiler/treeifier/ast.hh"
#include <sstream>
namespace ppc::comp::tree::ast::conv { namespace ppc::comp::tree::ast::conv {
data::map_t identifier_to_map(const located_t<std::string> &loc) { 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 "compiler/treeifier/ast/helper.hh"
#include <map>
#include <algorithm> #include <algorithm>
#include <map>
enum precedence_t { enum precedence_t {
NONE, 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) { 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()) { while (!op_stack.empty()) {
auto &back_data = op_stack.back(); auto &back_data = op_stack.back();
if (data.assoc ? if (data.assoc ? back_data.precedence >= data.precedence : back_data.precedence > data.precedence) break;
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."); 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()) { if (h.curr().is_int_literal()) {
auto &arr = out["content"].array({}); 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()); out["location"] = conv::loc_to_map(h.loc());
return h.submit(true); 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()) { if (h.curr().is_str_literal()) {
auto &arr = out["content"].array({}); 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()); out["location"] = conv::loc_to_map(h.loc());
return h.submit(true); 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({})); h.force_parse(parse_identifier, "Expected an identifier.", member_access["name"].map({}));
member_access["location"] = conv::loc_to_map( member_access["location"] = conv::loc_to_map(
conv::map_to_loc(member_access["name"].map()["location"].string()).intersect( conv::map_to_loc(member_access["name"].map()["location"].string())
conv::map_to_loc(res.back().map()["location"].string()) .intersect(conv::map_to_loc(res.back().map()["location"].string()))
)
); );
res.pop_back(); res.pop_back();
res.push_back(member_access); res.push_back(member_access);

View File

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

View File

@ -1,6 +1,6 @@
#include <sstream>
#include "compiler/treeifier/lexer.hh" #include "compiler/treeifier/lexer.hh"
#include "utils/message.hh" #include "utils/message.hh"
#include <sstream>
using namespace ppc; using namespace ppc;
using namespace ppc::messages; using namespace ppc::messages;
@ -214,7 +214,8 @@ std::vector<token_t> token_t::parse_file(ppc::messages::msg_stack_t &msg_stack,
std::vector<char> contents; std::vector<char> contents;
int c; 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() }); 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 "compiler/treeifier/tokenizer.hh"
#include <string>
using namespace ppc::comp::tree; using namespace ppc::comp::tree;
using namespace ppc::comp; 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/lexer.hh"
#include "compiler/treeifier/tokenizer.hh"
#include <algorithm>
#include <string>
using namespace ppc; using namespace ppc;
using namespace messages; using namespace messages;

View File

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

View File

@ -32,9 +32,15 @@ definition_t::definition_t(const definition_t &val) {
definition_t::~definition_t() { definition_t::~definition_t() {
switch (this->kind) { switch (this->kind) {
case FUNCTION: delete this->val.func; break; case FUNCTION:
case FIELD: delete this->val.field; break; delete this->val.func;
case STRUCT: delete this->val.str; break; 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) { 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) { statement_t statement_t::stack(int64_t stack) {
return { STACK, { .stack = stack }}; return { STACK, { .stack = stack } };
} }
statement_t statement_t::ret() { statement_t statement_t::ret() {
return { RETURN }; return { RETURN };

View File

@ -1,6 +1,9 @@
#include <vector>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <vector>
#include <string>
using namespace std::string_literals;
struct project_t { struct project_t {
std::string output; 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::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; int c;
while (true) { while (true) {
@ -49,10 +52,10 @@ project_t read_project(std::istream &f) {
int end_ch; int end_ch;
std::string name = read_str(f, " \v\t\r\n", "\n", end_ch); std::string name = read_str(f, " \v\t\r\n", "\n", end_ch);
std::size_t cap = 16, n = 0; std::size_t cap = 16, n = 0;
std::vector<std::string> deps { }; std::vector<std::string> deps {};
if (name.length() == 0) { 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) { 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) { 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) { while (true) {
std::string dep = read_str(f, " \v\t\r\n", ",\n", end_ch); std::string dep = read_str(f, " \v\t\r\n", ",\n", end_ch);
if (dep.find(' ') != std::string::npos) { 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()) { if (dep.length()) {
@ -90,38 +93,38 @@ void print_err(const std::string &error, const std::string &context) {
std::cerr << context << ": " << error; std::cerr << context << ": " << error;
} }
int main(int argc, const char* argv[]) { int main(int argc, const char *argv[]) {
std::string proj_name = ""; std::string proj_name = "";
try { try {
argc--; argc--;
argv++; argv++;
if (argc != 3) { 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]; proj_name = argv[1];
std::ifstream f { proj_path, std::ios_base::in }; std::ifstream f { proj_path, std::ios_base::in };
if (!f.is_open()) { 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); project_t project = read_project(f);
f.close(); f.close();
if ((std::string)argv[2] == "output") { if ((std::string) argv[2] == "output") {
std::cout << project.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) { for (std::string dep : project.deps) {
std::cout << dep << " "; std::cout << dep << " ";
} }
} }
else { else {
throw (std::string)"Invalid command given. Available commands: output, deps."; throw "Invalid command given. Available commands: output, deps."s;
} }
std::cout << std::endl; std::cout << std::endl;

View File

@ -8,25 +8,25 @@
#define DISABLE_NEWLINE_AUTO_RETURN 0x8 #define DISABLE_NEWLINE_AUTO_RETURN 0x8
#endif #endif
#include <windows.h>
#include <conio.h> #include <conio.h>
#include <windows.h>
#undef ERROR #undef ERROR
#undef INFO #undef INFO
#endif #endif
#include <sstream> #include "./opions.hh"
#include <fstream> #include "compiler/treeifier/ast.hh"
#include <iostream>
#include <cstdio>
#include "utils/threading.hh"
#include "utils/strings.hh"
#include "utils/json.hh"
#include "compiler/treeifier/lexer.hh" #include "compiler/treeifier/lexer.hh"
#include "compiler/treeifier/tokenizer.hh" #include "compiler/treeifier/tokenizer.hh"
#include "compiler/treeifier/ast.hh" #include "utils/json.hh"
#include "./opions.hh" #include "utils/strings.hh"
#include "utils/threading.hh"
#include <cstdio>
#include <fstream>
#include <iostream>
#include <sstream>
using std::cout; using std::cout;
using std::size_t; using std::size_t;
@ -35,79 +35,79 @@ using namespace ppc::comp::tree;
using namespace ppc::comp::tree::ast; using namespace ppc::comp::tree::ast;
void add_flags(options::parser_t &parser) { void add_flags(options::parser_t &parser) {
parser.add_flag({ parser.add_flag({ .name = "version",
.name = "version", .shorthands = "v",
.shorthands = "v", .description = "Displays version and license agreement of this binary",
.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) {
.execute = [](options::parser_t &parser, const std::string &option, ppc::messages::msg_stack_t &global_stack) { cout << "++C compiler\n"
cout << "++C compiler\n" << " Version: v" << PPC_VERSION_MAJOR << '.' << PPC_VERSION_MINOR << '.' << PPC_VERSION_BUILD
<< " Version: v" << PPC_VERSION_MAJOR << '.' << PPC_VERSION_MINOR << '.' << PPC_VERSION_BUILD #if WINDOWS
#if WINDOWS << " (Windows)"
<< " (Windows)" #elif LINUX
#elif LINUX
<< " (Linux)" << " (Linux)"
#endif #endif
<< "\n" << "\n"
<< " License: MIT Copyright (C) TopchetoEU\n"; << " License: MIT Copyright (C) TopchetoEU\n";
exit(0); exit(0);
} } });
}); parser.add_flag({ .name = "help",
parser.add_flag({ .shorthands = "h",
.name = "help", .description = "Displays a list of all flags and their meaning",
.shorthands = "h", .execute = [](options::parser_t &parser, const std::string &option, ppc::messages::msg_stack_t &global_stack) {
.description = "Displays a list of all flags and their meaning", cout << "Usage: ...flags ...files\n\n"
.execute = [](options::parser_t &parser, const std::string &option, ppc::messages::msg_stack_t &global_stack) { << "Flags and file names can be interlaced\n"
cout << "Usage: ...flags ...files\n\n" << "Flags will execute in the order they're written, then compilation begins\n\n"
<< "Flags and file names can be interlaced\n" << "Flags:\n";
<< "Flags will execute in the order they're written, then compilation begins\n\n"
<< "Flags:\n";
for (const auto &flag : parser) { for (const auto &flag : parser) {
std::stringstream buff; std::stringstream buff;
buff << " --" << flag.name; buff << " --" << flag.name;
if (flag.match_type) buff << "=..."; if (flag.match_type) buff << "=...";
if (flag.shorthands.size()) { if (flag.shorthands.size()) {
buff << " ("; buff << " (";
bool first = true; bool first = true;
for (char shorthand : flag.shorthands) { for (char shorthand : flag.shorthands) {
if (!first) buff << ","; if (!first) buff << ",";
else first = false; else first = false;
buff << " -"; buff << " -";
buff << std::string { shorthand }; buff << std::string { shorthand };
} }
buff << ")"; buff << ")";
} }
buff << " "; buff << " ";
cout << buff.str(); cout << buff.str();
size_t n = buff.str().length(); size_t n = buff.str().length();
if (flag.description.size()) { if (flag.description.size()) {
const size_t padding = 24; const size_t padding = 24;
const size_t msg_width = 80 - padding; 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 i = 0; i < len / msg_width; i++) {
for (size_t j = 0; j < msg_width; j++) cout << flag.description[i * msg_width + j]; for (size_t j = 0; j < msg_width; j++)
cout << std::endl; cout << flag.description[i * msg_width + j];
for (size_t j = 0; j < padding; j++) cout << ' '; 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({ parser.add_flag({
.name = "silent", .name = "silent",
.shorthands = "qs", .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'", .description = "Sets a lower limit of messages that will print. Accepted values: 'all', 'debug', 'suggestion', 'info', 'warning', 'error', 'none'",
.match_type = options::MATCH_PREFIX, .match_type = options::MATCH_PREFIX,
}); });
parser.add_flag({ parser.add_flag({ .name = "print-what",
.name = "print-what", .description = "Prints a 'what?' type of message (you'll see)",
.description = "Prints a 'what?' type of message (you'll see)", .match_type = options::MATCH_PREFIX,
.match_type = options::MATCH_PREFIX, .execute = [](options::parser_t &parser, const std::string &option, ppc::messages::msg_stack_t &global_stack) {
.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."));
global_stack.push(messages::message_t((messages::message_t::level_t)69, "IDK LOL.")); } });
}
});
} }
int main(int argc, const char *argv[]) { int main(int argc, const char *argv[]) {
#ifdef WINDOWS #ifdef WINDOWS
HANDLE handleOut = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE handleOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD consoleMode; DWORD consoleMode;
GetConsoleMode(handleOut, &consoleMode); GetConsoleMode(handleOut, &consoleMode);
consoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; consoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
consoleMode |= DISABLE_NEWLINE_AUTO_RETURN; consoleMode |= DISABLE_NEWLINE_AUTO_RETURN;
SetConsoleMode(handleOut, consoleMode); 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; std::vector<std::string> files;
messages::msg_stack_t msg_stack; messages::msg_stack_t msg_stack;
@ -170,7 +168,7 @@ int main(int argc, const char *argv[]) {
catch (const messages::message_t &msg) { catch (const messages::message_t &msg) {
msg_stack.push(msg); msg_stack.push(msg);
} }
#ifndef PROFILE_debug #ifndef PROFILE_debug
catch (const std::string &msg) { catch (const std::string &msg) {
msg_stack.push(message_t::error(msg)); msg_stack.push(message_t::error(msg));
} }
@ -178,7 +176,7 @@ int main(int argc, const char *argv[]) {
std::cout << std::endl; std::cout << std::endl;
msg_stack.push(message_t::error("A fatal error occurred.")); msg_stack.push(message_t::error("A fatal error occurred."));
} }
#endif #endif
msg_stack.print(std::cout, messages::message_t::DEBUG, true); msg_stack.print(std::cout, messages::message_t::DEBUG, true);

View File

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

View File

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

View File

@ -1,4 +1,7 @@
#include "utils/data.hh" #include "utils/data.hh"
#include <string>
using namespace std::string_literals;
namespace ppc::data { namespace ppc::data {
bool value_t::is_null() const { bool value_t::is_null() const {
@ -44,45 +47,45 @@ namespace ppc::data {
array_t &value_t::array() { array_t &value_t::array() {
if (is_array()) return *val.arr; 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() { map_t &value_t::map() {
if (is_map()) return *val.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() { number_t &value_t::number() {
if (is_number()) return val.num; 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() { string_t &value_t::string() {
if (is_string()) return *val.str; 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() { bool_t &value_t::boolean() {
if (is_bool()) return val.bl; 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 { const array_t &value_t::array() const {
if (is_array()) return *val.arr; 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 { const map_t &value_t::map() const {
if (is_map()) return *val.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() const { number_t value_t::number() const {
if (is_number()) return val.num; 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 { const string_t &value_t::string() const {
if (is_string()) return *val.str; 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 { bool_t value_t::boolean() const {
if (is_bool()) return val.bl; 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() { 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 a = *this;
location_t b = other; 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); 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 = ""; std::string empty = "";
location_t::location_t(): 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(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::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(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->length = length;
this->code_start = code_start; this->code_start = code_start;
this->line = line; this->line = line;
this->start = start; 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 <iostream>
#include <sstream> #include <sstream>
#include "utils/message.hh"
using namespace ppc; using namespace ppc;
@ -10,15 +10,27 @@ namespace ppc::messages {
std::string level_readable; std::string level_readable;
switch (level) { switch (level) {
case message_t::DEBUG: level_readable = "debug"; break; case message_t::DEBUG:
case message_t::SUGGESTION: level_readable = "suggestion"; break; level_readable = "debug";
case message_t::INFO: level_readable = "info"; break; break;
case message_t::WARNING: level_readable = "warning"; break; case message_t::SUGGESTION:
case message_t::ERROR: level_readable = "error"; break; level_readable = "suggestion";
default: level_readable = "what?"; break; 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 << ": "; if (loc_readable.length()) res << loc_readable << ": ";
res << level_readable << ": " << content; res << level_readable << ": " << content;
@ -51,7 +63,7 @@ namespace ppc::messages {
output << (color_output ? "\e[38;5;45msuggestion: " : "suggestion: "); output << (color_output ? "\e[38;5;45msuggestion: " : "suggestion: ");
break; break;
case message_t::INFO: case message_t::INFO:
output << (color_output ? "\e[38;5;33minfo: ": "info: "); output << (color_output ? "\e[38;5;33minfo: " : "info: ");
break; break;
case message_t::WARNING: case message_t::WARNING:
output << (color_output ? "\e[38;5;214mwarning: " : "warning: "); output << (color_output ? "\e[38;5;214mwarning: " : "warning: ");

View File

@ -1,5 +1,5 @@
#include <sstream>
#include "utils/strings.hh" #include "utils/strings.hh"
#include <sstream>
using namespace ppc; using namespace ppc;
@ -14,7 +14,7 @@ std::vector<std::string> str::split(const std::string &splittable, std::initiali
else { else {
if (!buff.str().empty() || !remove_empty_entries) { if (!buff.str().empty() || !remove_empty_entries) {
res.push_back(buff.str()); 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) { threading::thread_t threading::thread_t::start_impl(void *func, void *args) {
DWORD id; 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; if (!hnd) throw "Couldn't create thread."s;
return { hnd }; return { hnd };
@ -31,14 +31,14 @@ threading::thread_t::~thread_t() {
threading::thread_t threading::thread_t::start_impl(void *func, void *args) { threading::thread_t threading::thread_t::start_impl(void *func, void *args) {
pthread_t *handle = new pthread_t; pthread_t *handle = new pthread_t;
pthread_create(handle, nullptr, (void* (*)(void *))func, args); pthread_create(handle, nullptr, (void *(*) (void *) ) func, args);
return { handle }; return { handle };
} }
int threading::thread_t::join() const { 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() { threading::thread_t::~thread_t() {
delete (pthread_t*)handle; delete (pthread_t *) handle;
} }
#endif #endif