Create a generic type for types with an error list
This commit is contained in:
@ -17,7 +17,6 @@ along with GCC; see the file COPYING3. If not see
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <optional>
|
||||
#include "elna/boot/ast.h"
|
||||
#include "location.hh"
|
||||
@ -39,18 +38,12 @@ namespace boot
|
||||
virtual std::string what() const override;
|
||||
};
|
||||
|
||||
class driver
|
||||
class driver : public error_container
|
||||
{
|
||||
std::list<std::unique_ptr<struct error>> m_errors;
|
||||
const char *input_file;
|
||||
|
||||
public:
|
||||
std::unique_ptr<program> tree;
|
||||
|
||||
driver(const char *input_file);
|
||||
|
||||
void error(const yy::location& loc, const std::string& message);
|
||||
const std::list<std::unique_ptr<struct error>>& errors() const noexcept;
|
||||
};
|
||||
|
||||
constexpr char escape_invalid_char = '\xff';
|
||||
|
@ -19,6 +19,8 @@ along with GCC; see the file COPYING3. If not see
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
|
||||
namespace elna
|
||||
{
|
||||
@ -59,5 +61,25 @@ namespace boot
|
||||
/// Error column in the source text.
|
||||
std::size_t column() const;
|
||||
};
|
||||
|
||||
class error_container
|
||||
{
|
||||
protected:
|
||||
std::deque<std::unique_ptr<error>> m_errors;
|
||||
|
||||
error_container(const char *input_file);
|
||||
|
||||
public:
|
||||
const char *input_file;
|
||||
|
||||
std::deque<std::unique_ptr<error>>& errors();
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void add_error(Args... arguments)
|
||||
{
|
||||
auto new_error = std::make_unique<T>(arguments...);
|
||||
m_errors.emplace_back(std::move(new_error));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ along with GCC; see the file COPYING3. If not see
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
#include <deque>
|
||||
|
||||
#include "elna/boot/ast.h"
|
||||
#include "elna/boot/result.h"
|
||||
@ -37,12 +38,10 @@ namespace boot
|
||||
virtual std::string what() const override;
|
||||
};
|
||||
|
||||
class declaration_visitor final : public empty_visitor
|
||||
class declaration_visitor final : public empty_visitor, public error_container
|
||||
{
|
||||
type current_type;
|
||||
const char *path;
|
||||
symbol_table symbols;
|
||||
std::vector<std::unique_ptr<error>> errors;
|
||||
|
||||
public:
|
||||
std::unordered_map<std::string, std::shared_ptr<alias_type>> unresolved;
|
||||
|
@ -22,6 +22,10 @@ along with GCC; see the file COPYING3. If not see
|
||||
#include "coretypes.h"
|
||||
#include "input.h"
|
||||
#include "tree.h"
|
||||
#include "diagnostic.h"
|
||||
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
|
||||
#include "elna/boot/result.h"
|
||||
|
||||
@ -30,7 +34,7 @@ namespace elna
|
||||
namespace gcc
|
||||
{
|
||||
location_t get_location(const boot::position *position);
|
||||
|
||||
std::string print_type(tree type);
|
||||
void report_errors(const std::deque<std::unique_ptr<boot::error>>& errors);
|
||||
}
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ namespace elna
|
||||
{
|
||||
namespace gcc
|
||||
{
|
||||
void do_semantic_analysis(const char *path, std::unique_ptr<boot::program>& ast,
|
||||
std::shared_ptr<symbol_table> symbols);
|
||||
std::deque<std::unique_ptr<boot::error>> do_semantic_analysis(const char *path,
|
||||
std::unique_ptr<boot::program>& ast, std::shared_ptr<symbol_table> symbols);
|
||||
|
||||
class generic_visitor final : public boot::empty_visitor
|
||||
{
|
||||
|
Reference in New Issue
Block a user