elna/include/elna/result.hpp

72 lines
1.3 KiB
C++

#pragma once
#include <cstddef>
#include <boost/outcome.hpp>
namespace elna
{
/**
* Position in the source text.
*/
struct Position
{
/// Line.
std::size_t line = 1;
/// Column.
std::size_t column = 1;
};
/**
* A compilation error consists of an error message and position.
*/
struct CompileError
{
private:
char const *message;
Position position;
public:
/**
* @param message Error text.
* @param position Error position in the source text.
*/
CompileError(char const *message, const Position position) noexcept;
/// Error text.
const char *what() const noexcept;
/// Error line in the source text.
std::size_t line() const noexcept;
/// Error column in the source text.
std::size_t column() const noexcept;
};
template<typename T>
using result = boost::outcome_v2::result<T, CompileError>;
enum class Target
{
text,
high20,
lower12i
};
struct Reference
{
const char* name;
size_t offset;
Target target;
};
struct Symbol
{
Symbol(const char *name);
const char *name;
unsigned char *text;
std::size_t length;
Reference symbols[3];
};
}