Compare commits
6
Commits
8345f67c50
...
9390f4fd31
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9390f4fd31 | ||
|
|
7d2c2c52e2 | ||
|
|
bcea91a2c0 | ||
|
|
fc163f7f06 | ||
|
|
9857f11798 | ||
|
|
da5dce22e6 |
+2
-1
@@ -17,6 +17,7 @@ AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
IndentPPDirectives: BeforeHash
|
||||
|
||||
BraceWrapping:
|
||||
AfterEnum: false
|
||||
@@ -32,7 +33,7 @@ SpaceAfterTemplateKeyword: false
|
||||
SpaceInEmptyBlock: false
|
||||
NamespaceIndentation: None
|
||||
FixNamespaceComments: true
|
||||
Standard: c++17
|
||||
Standard: c++20
|
||||
TabWidth: 4
|
||||
UseTab: AlignWithSpaces
|
||||
...
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ include(GNUInstallDirs)
|
||||
# ------------------------------------------
|
||||
# Setup C++ compiler
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
|
||||
@@ -136,6 +136,7 @@ void strln(std::string& fill, std::string_view format, const Parameters&... para
|
||||
std::stringstream stream;
|
||||
VariadicParameters variadicParameters { parameters... };
|
||||
variadicFormat(stream, format, variadicParameters);
|
||||
stream << '\n';
|
||||
fill = stream.str();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +38,7 @@ bool GenericLexer::isEOF() const
|
||||
|
||||
char GenericLexer::peek(size_t offset) const
|
||||
{
|
||||
return (m_index + offset >= 0 && m_index + offset < m_input.length())
|
||||
? m_input[m_index + offset]
|
||||
: '\0';
|
||||
return (m_index + offset < m_input.length()) ? m_input[m_index + offset] : '\0';
|
||||
}
|
||||
|
||||
void GenericLexer::ignore(size_t count)
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Riyyi
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef> // size_t
|
||||
#include <cstdint> // uint32_t
|
||||
#include <cstring> // strlen
|
||||
#include <fstream> // ifstream
|
||||
#include <string>
|
||||
|
||||
#include "util/format/format.h"
|
||||
#include "util/meta/compiler.h"
|
||||
|
||||
#define CRASH() asm volatile("int $0x03");
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define VERIFY(expr, ...) (static_cast<bool>(expr) ? (void)0 : Util::__assertion_failed(#expr, __FILE__, __LINE__, FUNCTION_MACRO __VA_OPT__(, ) __VA_ARGS__))
|
||||
#define VERIFY_NOT_REACHED() VERIFY(false)
|
||||
#else
|
||||
#define VERIFY(expr, ...) (static_cast<bool>(expr) ? (void)0 : CRASH()
|
||||
#define VERIFY_NOT_REACHED() CRASH()
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
namespace Util {
|
||||
|
||||
template<typename... Parameters>
|
||||
inline void __assertion_failed(const char* assertion, const char* file, uint32_t line, const char* function, const Parameters&... parameters)
|
||||
{
|
||||
// Get the line that caused the error
|
||||
std::ifstream source(file);
|
||||
std::string content;
|
||||
if (source.is_open()) {
|
||||
for (uint32_t i = 0; std::getline(source, content); ++i) {
|
||||
if (i == line - 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Replace tab indentation with spaces
|
||||
size_t tabs = content.find_first_not_of('\t');
|
||||
if (tabs > 0 && tabs < content.size()) {
|
||||
content = std::string(tabs * 4, ' ') + content.substr(tabs);
|
||||
}
|
||||
|
||||
// Find the assertion in the line
|
||||
size_t column = content.find(assertion);
|
||||
size_t assertionLength = strlen(assertion);
|
||||
if (column == std::string::npos) {
|
||||
column = content.find_first_not_of(' ');
|
||||
assertionLength = content.length() - column;
|
||||
}
|
||||
|
||||
// Error message
|
||||
fprintf(stderr,
|
||||
"\033[;1m%s:%u:%zu "
|
||||
"\033[31;1merror: "
|
||||
"\033[0massertion failed",
|
||||
file, line, column + 1);
|
||||
if constexpr (sizeof...(Parameters) > 0) {
|
||||
fprintf(stderr, ": ");
|
||||
// Cant use the formatting library to print asserts caused by the formatting library
|
||||
if (!std::string_view(function).starts_with("Util::Format::")) {
|
||||
std::string message;
|
||||
strln(message, parameters...);
|
||||
fprintf(stderr, "%s", message.c_str());
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, parameters...);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
// Code line
|
||||
fprintf(stderr, " %u | %s\033[31;1m%s\033[0m%s\n", line,
|
||||
content.substr(0, column).c_str(), // Whitespace at front
|
||||
content.substr(column, assertionLength).c_str(), // Error portion
|
||||
content.substr(column + assertionLength).c_str()); // Rest of the line
|
||||
|
||||
// Arrow pointer
|
||||
fprintf(stderr, " %s | %s\033[31;1m^%s\033[0m\n",
|
||||
std::string(std::to_string(line).length(), ' ').c_str(), // Line number spacing
|
||||
std::string(column, ' ').c_str(), // Content spacing
|
||||
std::string(assertionLength - 1, '~').c_str()); // Arrow pointer
|
||||
|
||||
CRASH();
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Riyyi
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Compiler
|
||||
#if defined(__clang__)
|
||||
#define GCC
|
||||
#elif defined(__GNUG__) || (defined(__GNUC__) && defined(__cplusplus))
|
||||
#define GCC
|
||||
#elif defined(__INTEL_COMPILER) // Supports some GCC extensions
|
||||
#define GCC
|
||||
#elif defined(_MSC_VER)
|
||||
#define MSVC
|
||||
#endif
|
||||
|
||||
// Non-standard function macro
|
||||
#ifdef GCC
|
||||
#define FUNCTION_MACRO __PRETTY_FUNCTION__ // GCC extension
|
||||
#elif MSVC
|
||||
#define FUNCTION_MACRO __FUNCSIG__
|
||||
#else
|
||||
#define FUNCTION_MACRO __func__ // C99
|
||||
#endif
|
||||
Reference in New Issue
Block a user