Add an error message when an exception is thrown from the getFileContent() function & --parallel is not in use, and support MSVC

This commit is contained in:
Username404-59 2021-12-15 17:25:39 +01:00
parent b42cf6953b
commit 9824dfc7fd
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
5 changed files with 12 additions and 6 deletions

View File

@ -1,14 +1,15 @@
#include <fstream>
#include <iostream>
#include <cstring>
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;
}

View File

@ -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 <version>
#if not defined(__cpp_lib_concepts) || not defined(__cpp_lib_integer_comparison_functions)
#error "The current standard library is incomplete"

View File

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

View File

@ -16,7 +16,7 @@ using namespace std;
#include <concepts>
#define IS(X) template<derived_from<X> 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;
};

View File

@ -46,8 +46,8 @@ int main(int argc, char* argv[]) {
}
}
const auto currentTarget = Target::forName(target, newLines);
const auto compile = [&target, &currentTarget](string_view name) -> string {
string transpiledString = currentTarget->transpileWithTree(parseString(getFileContent(name.data())));
const auto compile = [&target, &currentTarget, &parallel](string_view name) -> string {
string transpiledString = currentTarget->transpileWithTree(parseString(getFileContent(name.data(), parallel)));
name.remove_suffix(6);
string outputFile;
(outputFile = name).append(target);