74 lines
1.7 KiB
C++
74 lines
1.7 KiB
C++
// This Source Code Form is subject to the terms of the Mozilla Public License
|
|
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
|
// obtain one at http://mozilla.org/MPL/2.0/.
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include "elna/source/types.h"
|
|
|
|
namespace elna
|
|
{
|
|
namespace source
|
|
{
|
|
/**
|
|
* 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.
|
|
*/
|
|
class error
|
|
{
|
|
protected:
|
|
/**
|
|
* Constructs an error.
|
|
*
|
|
* \param path Source file name.
|
|
* \param position Error position in the source text.
|
|
*/
|
|
error(const char *path, const struct position position);
|
|
|
|
public:
|
|
const struct position position;
|
|
const char *path;
|
|
|
|
virtual ~error() noexcept = default;
|
|
|
|
/// Error text.
|
|
virtual std::string what() const = 0;
|
|
|
|
/// Error line in the source text.
|
|
std::size_t line() const noexcept;
|
|
|
|
/// Error column in the source text.
|
|
std::size_t column() const noexcept;
|
|
};
|
|
|
|
class name_collision final : public error
|
|
{
|
|
const struct position previous;
|
|
std::string name;
|
|
|
|
public:
|
|
/**
|
|
* \param name Symbol name.
|
|
* \param path Source file name.
|
|
* \param current Current symbol position.
|
|
* \param previous Position of the previously defined symbol.
|
|
*/
|
|
name_collision(const std::string& name, const char *path,
|
|
const struct position current, const struct position previous);
|
|
|
|
std::string what() const override;
|
|
};
|
|
}
|
|
}
|