Detect type aliasing cycles
This commit is contained in:
@ -21,7 +21,6 @@ along with GCC; see the file COPYING3. If not see
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <variant>
|
||||
#include "elna/boot/result.h"
|
||||
|
||||
namespace elna::boot
|
||||
@ -316,30 +315,19 @@ namespace elna::boot
|
||||
virtual ~constant_definition() override;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tags a procedure type as never returning.
|
||||
*/
|
||||
struct return_declaration
|
||||
{
|
||||
return_declaration() = default;
|
||||
explicit return_declaration(std::shared_ptr<type_expression> type);
|
||||
explicit return_declaration(std::monostate);
|
||||
|
||||
std::shared_ptr<type_expression> type{ nullptr };
|
||||
bool no_return{ false };
|
||||
};
|
||||
|
||||
/**
|
||||
* Procedure type.
|
||||
*/
|
||||
class procedure_type_expression : public type_expression
|
||||
{
|
||||
public:
|
||||
const return_declaration return_type;
|
||||
using return_t = return_declaration<std::shared_ptr<type_expression>>;
|
||||
|
||||
const return_t return_type;
|
||||
std::vector<std::shared_ptr<type_expression>> parameters;
|
||||
|
||||
procedure_type_expression(const struct position position,
|
||||
return_declaration return_type = return_declaration());
|
||||
return_t return_type = return_t());
|
||||
|
||||
void accept(parser_visitor *visitor) override;
|
||||
std::shared_ptr<procedure_type_expression> is_procedure() override;
|
||||
|
@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see
|
||||
#include <string>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
|
||||
namespace elna::boot
|
||||
{
|
||||
@ -79,4 +80,27 @@ namespace elna::boot
|
||||
m_errors.emplace_back(std::move(new_error));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Tags a procedure type as never returning.
|
||||
*/
|
||||
template<typename T>
|
||||
struct return_declaration
|
||||
{
|
||||
return_declaration() = default;
|
||||
|
||||
explicit return_declaration(T type)
|
||||
: proper_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
explicit return_declaration(std::monostate)
|
||||
: no_return(true)
|
||||
{
|
||||
}
|
||||
|
||||
T proper_type{};
|
||||
bool no_return{ false };
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ namespace elna::boot
|
||||
void visit(type_definition *definition) override;
|
||||
void visit(record_type_expression *type_expression) override;
|
||||
void visit(union_type_expression *type_expression) override;
|
||||
void visit(procedure_type_expression *) override;
|
||||
void visit(procedure_type_expression *type_expression) override;
|
||||
|
||||
void visit(variable_declaration *declaration) override;
|
||||
void visit(constant_definition *) override;
|
||||
|
@ -23,6 +23,8 @@ along with GCC; see the file COPYING3. If not see
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "elna/boot/result.h"
|
||||
|
||||
namespace elna::boot
|
||||
{
|
||||
class alias_type;
|
||||
@ -73,6 +75,8 @@ namespace elna::boot
|
||||
type(type&& other);
|
||||
type& operator=(type&& other);
|
||||
|
||||
bool operator==(const std::nullptr_t&);
|
||||
|
||||
~type();
|
||||
|
||||
template<typename T>
|
||||
@ -123,6 +127,16 @@ namespace elna::boot
|
||||
std::vector<type_field> fields;
|
||||
};
|
||||
|
||||
struct procedure_type
|
||||
{
|
||||
using return_t = return_declaration<type>;
|
||||
|
||||
std::vector<type> parameters;
|
||||
const return_t return_type;
|
||||
|
||||
procedure_type(return_t return_type = return_t());
|
||||
};
|
||||
|
||||
class type_info;
|
||||
|
||||
class info : public std::enable_shared_from_this<info>
|
||||
|
@ -36,7 +36,8 @@ namespace elna::gcc
|
||||
std::unique_ptr<boot::program>& ast, std::shared_ptr<boot::symbol_table> info_table,
|
||||
std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved);
|
||||
tree handle_symbol(const std::string& symbol_name, std::shared_ptr<boot::alias_type> reference,
|
||||
std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved);
|
||||
std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved,
|
||||
std::vector<std::string>& path);
|
||||
|
||||
|
||||
class generic_visitor final : public boot::parser_visitor
|
||||
|
Reference in New Issue
Block a user