完成 Error定义和ErrorLog. 以及一些相关的东西
This commit is contained in:
5
src/Core/Core.hpp
Normal file
5
src/Core/Core.hpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <Core/CoreInfos.hpp>
|
||||
#include <Core/CoreIO.hpp>
|
||||
#include <Core/RuntimeTime.hpp>
|
||||
30
src/Core/CoreIO.cpp
Normal file
30
src/Core/CoreIO.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <Core/CoreIO.hpp>
|
||||
#include <Core/CoreInfos.hpp>
|
||||
|
||||
namespace Fig::CoreIO
|
||||
{
|
||||
#if defined(_WIN32) || defined(__APPLE__) || defined (__linux__) || defined (__unix__)
|
||||
std::ostream &GetStdOut()
|
||||
{
|
||||
static std::ostream &out = std::cout;
|
||||
return out;
|
||||
}
|
||||
std::ostream &GetStdErr()
|
||||
{
|
||||
static std::ostream &err = std::cerr;
|
||||
return err;
|
||||
}
|
||||
std::ostream &GetStdLog()
|
||||
{
|
||||
static std::ostream &log = std::clog;
|
||||
return log;
|
||||
}
|
||||
std::istream &GetStdCin()
|
||||
{
|
||||
static std::istream &cin = std::cin;
|
||||
return cin;
|
||||
}
|
||||
#else
|
||||
// link
|
||||
#endif
|
||||
};
|
||||
11
src/Core/CoreIO.hpp
Normal file
11
src/Core/CoreIO.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace Fig::CoreIO
|
||||
{
|
||||
std::ostream &GetStdOut();
|
||||
std::ostream &GetStdErr();
|
||||
std::ostream &GetStdLog();
|
||||
std::istream &GetStdCin();
|
||||
};
|
||||
60
src/Core/CoreInfos.hpp
Normal file
60
src/Core/CoreInfos.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include <Deps/String/String.hpp>
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
#define __FCORE_VERSION "0.5.0-alpha"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define __FCORE_PLATFORM "Windows"
|
||||
#elif defined(__APPLE__)
|
||||
#define __FCORE_PLATFORM "Apple"
|
||||
#elif defined(__linux__)
|
||||
#define __FCORE_PLATFORM "Linux"
|
||||
#elif defined(__unix__)
|
||||
#define __FCORE_PLATFORM "Unix"
|
||||
#else
|
||||
#define __FCORE_PLATFORM "Unknown"
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if defined(_WIN32)
|
||||
#if defined(__clang__)
|
||||
#define __FCORE_COMPILER "llvm-mingw"
|
||||
#else
|
||||
#define __FCORE_COMPILER "MinGW"
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define __FCORE_COMPILER "GCC"
|
||||
#endif
|
||||
#elif defined(__clang__)
|
||||
#define __FCORE_COMPILER "Clang"
|
||||
#elif defined(_MSC_VER)
|
||||
#define __FCORE_COMPILER "MSVC"
|
||||
#else
|
||||
#define __FCORE_COMPILER "Unknown"
|
||||
#endif
|
||||
|
||||
#if SIZE_MAX == 18446744073709551615ull
|
||||
#define __FCORE_ARCH "64"
|
||||
#else
|
||||
#define __FCORE_ARCH "86"
|
||||
#endif
|
||||
|
||||
#define __FCORE_LINK_DEPS
|
||||
|
||||
namespace Fig
|
||||
{
|
||||
namespace Core
|
||||
{
|
||||
inline constexpr std::string_view VERSION = __FCORE_VERSION;
|
||||
inline constexpr std::string_view LICENSE = "MIT";
|
||||
inline constexpr std::string_view AUTHOR = "PuqiAR";
|
||||
inline constexpr std::string_view PLATFORM = __FCORE_PLATFORM;
|
||||
inline constexpr std::string_view COMPILER = __FCORE_COMPILER;
|
||||
inline constexpr std::string_view COMPILE_TIME = __FCORE_COMPILE_TIME;
|
||||
inline constexpr std::string_view ARCH = __FCORE_ARCH;
|
||||
}; // namespace Core
|
||||
}; // namespace Fig
|
||||
18
src/Core/RuntimeTime.cpp
Normal file
18
src/Core/RuntimeTime.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <Core/RuntimeTime.hpp>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace Fig::Time
|
||||
{
|
||||
Clock::time_point start_time;
|
||||
void init()
|
||||
{
|
||||
static bool flag = false;
|
||||
if (flag)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
start_time = Clock::now();
|
||||
flag = true;
|
||||
}
|
||||
};
|
||||
10
src/Core/RuntimeTime.hpp
Normal file
10
src/Core/RuntimeTime.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace Fig::Time
|
||||
{
|
||||
using Clock = std::chrono::steady_clock;
|
||||
extern Clock::time_point start_time; // since process start
|
||||
void init();
|
||||
};
|
||||
53
src/Core/SourceLocations.hpp
Normal file
53
src/Core/SourceLocations.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <Deps/Deps.hpp>
|
||||
#include <format>
|
||||
|
||||
namespace Fig
|
||||
{
|
||||
struct SourcePosition
|
||||
{
|
||||
size_t line, column, tok_length;
|
||||
|
||||
SourcePosition() { line = column = tok_length = 0; }
|
||||
SourcePosition(size_t _line, size_t _column, size_t _tok_length)
|
||||
{
|
||||
line = _line;
|
||||
column = _column;
|
||||
tok_length = _tok_length;
|
||||
}
|
||||
};
|
||||
|
||||
struct SourceLocation
|
||||
{
|
||||
SourcePosition sp;
|
||||
|
||||
Deps::String fileName;
|
||||
Deps::String packageName;
|
||||
Deps::String functionName;
|
||||
|
||||
SourceLocation() {}
|
||||
SourceLocation(SourcePosition _sp,
|
||||
Deps::String _fileName,
|
||||
Deps::String _packageName,
|
||||
Deps::String _functionName)
|
||||
{
|
||||
sp = std::move(_sp);
|
||||
fileName = std::move(_fileName);
|
||||
packageName = std::move(_packageName);
|
||||
functionName = std::move(_functionName);
|
||||
}
|
||||
SourceLocation(size_t line,
|
||||
size_t column,
|
||||
size_t tok_length,
|
||||
Deps::String _fileName,
|
||||
Deps::String _packageName,
|
||||
Deps::String _functionName)
|
||||
{
|
||||
sp = SourcePosition(line, column, tok_length);
|
||||
fileName = std::move(_fileName);
|
||||
packageName = std::move(_packageName);
|
||||
functionName = std::move(_functionName);
|
||||
}
|
||||
};
|
||||
}; // namespace Fig
|
||||
Reference in New Issue
Block a user