From 9824dfc7fd0f175d2a3b3e262be1729d22e7e34b Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Wed, 15 Dec 2021 17:25:39 +0100 Subject: [PATCH] Add an error message when an exception is thrown from the getFileContent() function & --parallel is not in use, and support MSVC --- src/etc/filefuncs.cpp | 5 +++-- src/headers/Yerbacon.hpp | 5 +++++ src/headers/misc.hpp | 2 +- src/headers/parsing/ParseComponents.hpp | 2 +- src/main.cpp | 4 ++-- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/etc/filefuncs.cpp b/src/etc/filefuncs.cpp index 227662b..2e81c9d 100644 --- a/src/etc/filefuncs.cpp +++ b/src/etc/filefuncs.cpp @@ -1,14 +1,15 @@ #include #include +#include using namespace std; -string getFileContent(const string& file) +string getFileContent(const string& file, const bool& parallel) { ifstream fileStream(file, ios::in); string lineinput, fullinput; if (fileStream.is_open()) while (getline(fileStream, lineinput)) { fullinput.append(lineinput += '\n'); - } else throw Yerbacon::Exception("Could not open \"" + file + "\"."); + } else throw Yerbacon::Exception("Could not open \"" + file + "\"" + ((not parallel) ? string(" : ").append(strerror(errno)) : ".")); // TODO: Use a thread-safe function when the parallel mode is in use fileStream.close(); return fullinput; } diff --git a/src/headers/Yerbacon.hpp b/src/headers/Yerbacon.hpp index adb5abd..b1c09f2 100644 --- a/src/headers/Yerbacon.hpp +++ b/src/headers/Yerbacon.hpp @@ -18,6 +18,11 @@ #error "A valid std::threads implementation is required" #endif +#ifdef _MSC_VER +// #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1 +#define _CRT_SECURE_NO_WARNINGS 1 +#endif + #include #if not defined(__cpp_lib_concepts) || not defined(__cpp_lib_integer_comparison_functions) #error "The current standard library is incomplete" diff --git a/src/headers/misc.hpp b/src/headers/misc.hpp index 0962dee..75ab17b 100644 --- a/src/headers/misc.hpp +++ b/src/headers/misc.hpp @@ -1,7 +1,7 @@ #ifndef YERBACON_MISC_HPP #define YERBACON_MISC_HPP -string getFileContent(const string& file); +string getFileContent(const string& file, const bool& parallel); void outputFileContent(const string& file, string_view content); #include "lex.hpp" diff --git a/src/headers/parsing/ParseComponents.hpp b/src/headers/parsing/ParseComponents.hpp index 9d708c0..71c168a 100644 --- a/src/headers/parsing/ParseComponents.hpp +++ b/src/headers/parsing/ParseComponents.hpp @@ -16,7 +16,7 @@ using namespace std; #include #define IS(X) template T = X> struct ParseComponent { - [[nodiscard]] constexpr const type_info& getId() const { return typeid(*this); } + [[nodiscard]] inline const type_info& getId() const { return typeid(*this); } virtual ~ParseComponent() = default; }; diff --git a/src/main.cpp b/src/main.cpp index 2d44c21..2fb3f81 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,8 +46,8 @@ int main(int argc, char* argv[]) { } } const auto currentTarget = Target::forName(target, newLines); - const auto compile = [&target, ¤tTarget](string_view name) -> string { - string transpiledString = currentTarget->transpileWithTree(parseString(getFileContent(name.data()))); + const auto compile = [&target, ¤tTarget, ¶llel](string_view name) -> string { + string transpiledString = currentTarget->transpileWithTree(parseString(getFileContent(name.data(), parallel))); name.remove_suffix(6); string outputFile; (outputFile = name).append(target);