Skip parameter names in procedure type expressions

This commit is contained in:
2025-03-18 11:37:10 +01:00
parent 6eb4e91b2c
commit 4a0ff945fa
20 changed files with 196 additions and 237 deletions

View File

@ -21,11 +21,10 @@ 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
{
namespace boot
namespace elna::boot
{
enum class binary_operator
{
@ -80,9 +79,9 @@ namespace boot
class field_access_expression;
class dereference_expression;
class designator_expression;
class literal;
class literal_expression;
template<typename T>
class number_literal;
class literal;
class defer_statement;
/**
@ -116,13 +115,13 @@ namespace boot
virtual void visit(array_access_expression *) = 0;
virtual void visit(field_access_expression *) = 0;
virtual void visit(dereference_expression *) = 0;
virtual void visit(number_literal<std::int32_t> *) = 0;
virtual void visit(number_literal<std::uint32_t> *) = 0;
virtual void visit(number_literal<double> *) = 0;
virtual void visit(number_literal<bool> *) = 0;
virtual void visit(number_literal<unsigned char> *) = 0;
virtual void visit(number_literal<std::nullptr_t> *) = 0;
virtual void visit(number_literal<std::string> *) = 0;
virtual void visit(literal<std::int32_t> *) = 0;
virtual void visit(literal<std::uint32_t> *) = 0;
virtual void visit(literal<double> *) = 0;
virtual void visit(literal<bool> *) = 0;
virtual void visit(literal<unsigned char> *) = 0;
virtual void visit(literal<std::nullptr_t> *) = 0;
virtual void visit(literal<std::string> *) = 0;
};
/**
@ -156,13 +155,13 @@ namespace boot
virtual void visit(array_access_expression *) override;
virtual void visit(field_access_expression *) override;
virtual void visit(dereference_expression *) override;
virtual void visit(number_literal<std::int32_t> *) override;
virtual void visit(number_literal<std::uint32_t> *) override;
virtual void visit(number_literal<double> *) override;
virtual void visit(number_literal<bool> *) override;
virtual void visit(number_literal<unsigned char> *) override;
virtual void visit(number_literal<std::nullptr_t> *) override;
virtual void visit(number_literal<std::string> *) override;
virtual void visit(literal<std::int32_t> *) override;
virtual void visit(literal<std::uint32_t> *) override;
virtual void visit(literal<double> *) override;
virtual void visit(literal<bool> *) override;
virtual void visit(literal<unsigned char> *) override;
virtual void visit(literal<std::nullptr_t> *) override;
virtual void visit(literal<std::string> *) override;
};
/**
@ -213,7 +212,7 @@ namespace boot
virtual unary_expression *is_unary();
virtual designator_expression *is_designator();
virtual procedure_call *is_call_expression();
virtual literal *is_literal();
virtual literal_expression *is_literal();
void accept(parser_visitor *visitor);
~expression() = 0;
@ -336,22 +335,22 @@ namespace boot
/**
* Literal expression.
*/
class literal : public expression
class literal_expression : public expression
{
public:
virtual number_literal<std::int32_t> *is_int() = 0;
virtual number_literal<std::uint32_t> *is_word() = 0;
virtual number_literal<double> *is_float() = 0;
virtual number_literal<bool> *is_bool() = 0;
virtual number_literal<unsigned char> *is_char() = 0;
virtual number_literal<std::nullptr_t> *is_nil() = 0;
virtual number_literal<std::string> *is_string() = 0;
virtual literal<std::int32_t> *is_int() = 0;
virtual literal<std::uint32_t> *is_word() = 0;
virtual literal<double> *is_float() = 0;
virtual literal<bool> *is_bool() = 0;
virtual literal<unsigned char> *is_char() = 0;
virtual literal<std::nullptr_t> *is_nil() = 0;
virtual literal<std::string> *is_string() = 0;
literal *is_literal() override;
literal_expression *is_literal() override;
void accept(parser_visitor *visitor);
protected:
literal();
literal_expression();
};
/**
@ -359,7 +358,7 @@ namespace boot
*/
class constant_definition : public definition
{
literal *m_body;
literal_expression *m_body;
public:
/**
@ -368,10 +367,10 @@ namespace boot
* \param body Constant value.
*/
constant_definition(const struct position position, const std::string& identifier,
const bool exported, literal *body);
const bool exported, literal_expression *body);
void accept(parser_visitor *visitor);
literal& body();
literal_expression& body();
virtual ~constant_definition() override;
};
@ -379,10 +378,15 @@ namespace boot
/**
* Tags a procedure type as never returning.
*/
struct no_return_t
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 };
};
constexpr no_return_t no_return{};
/**
* Procedure type.
@ -390,18 +394,14 @@ namespace boot
class procedure_type_expression : public type_expression
{
public:
const std::shared_ptr<type_expression> return_type;
const bool no_return;
std::vector<variable_declaration *> parameters;
const return_declaration return_type;
std::vector<std::shared_ptr<type_expression>> parameters;
procedure_type_expression(const struct position position,
std::shared_ptr<type_expression> return_type = nullptr);
procedure_type_expression(const struct position position, no_return_t);
return_declaration return_type = return_declaration());
void accept(parser_visitor *visitor);
std::shared_ptr<procedure_type_expression> is_procedure() override;
virtual ~procedure_type_expression() override;
};
/**
@ -413,6 +413,7 @@ namespace boot
public:
block *const body;
std::vector<std::string> parameter_names;
procedure_definition(const struct position position, const std::string& identifier,
const bool exported, std::shared_ptr<procedure_type_expression> heading, block *body = nullptr);
@ -688,21 +689,21 @@ namespace boot
};
template<typename T>
class number_literal : public literal
class literal : public literal_expression
{
public:
T value;
number_literal(const struct position position, const T& value)
literal(const struct position position, const T& value)
: node(position), value(value)
{
}
number_literal<std::int32_t> *is_int() override
literal<std::int32_t> *is_int() override
{
if (std::is_same<T, std::int32_t>::value)
{
return reinterpret_cast<number_literal<std::int32_t> *>(this);
return reinterpret_cast<literal<std::int32_t> *>(this);
}
else
{
@ -710,11 +711,11 @@ namespace boot
}
}
number_literal<std::uint32_t> *is_word() override
literal<std::uint32_t> *is_word() override
{
if (std::is_same<T, std::uint32_t>::value)
{
return reinterpret_cast<number_literal<std::uint32_t> *>(this);
return reinterpret_cast<literal<std::uint32_t> *>(this);
}
else
{
@ -722,11 +723,11 @@ namespace boot
}
}
number_literal<double> *is_float() override
literal<double> *is_float() override
{
if (std::is_same<T, double>::value)
{
return reinterpret_cast<number_literal<double> *>(this);
return reinterpret_cast<literal<double> *>(this);
}
else
{
@ -734,11 +735,11 @@ namespace boot
}
}
number_literal<bool> *is_bool() override
literal<bool> *is_bool() override
{
if (std::is_same<T, bool>::value)
{
return reinterpret_cast<number_literal<bool> *>(this);
return reinterpret_cast<literal<bool> *>(this);
}
else
{
@ -746,11 +747,11 @@ namespace boot
}
}
number_literal<unsigned char> *is_char() override
literal<unsigned char> *is_char() override
{
if (std::is_same<T, unsigned char>::value)
{
return reinterpret_cast<number_literal<unsigned char> *>(this);
return reinterpret_cast<literal<unsigned char> *>(this);
}
else
{
@ -758,11 +759,11 @@ namespace boot
}
}
number_literal<std::nullptr_t> *is_nil() override
literal<std::nullptr_t> *is_nil() override
{
if (std::is_same<T, std::nullptr_t>::value)
{
return reinterpret_cast<number_literal<std::nullptr_t> *>(this);
return reinterpret_cast<literal<std::nullptr_t> *>(this);
}
else
{
@ -770,11 +771,11 @@ namespace boot
}
}
number_literal<std::string> *is_string() override
literal<std::string> *is_string() override
{
if (std::is_same<T, std::string>::value)
{
return reinterpret_cast<number_literal<std::string> *>(this);
return reinterpret_cast<literal<std::string> *>(this);
}
else
{
@ -840,4 +841,3 @@ namespace boot
const char *print_binary_operator(const binary_operator operation);
}
}

View File

@ -21,9 +21,7 @@ along with GCC; see the file COPYING3. If not see
#include "elna/boot/ast.h"
#include "location.hh"
namespace elna
{
namespace boot
namespace elna::boot
{
position make_position(const yy::location& location);
@ -50,4 +48,3 @@ namespace boot
char escape_char(char escape);
}
}

View File

@ -22,9 +22,7 @@ along with GCC; see the file COPYING3. If not see
#include <deque>
#include <memory>
namespace elna
{
namespace boot
namespace elna::boot
{
/**
* Position in the source text.
@ -82,4 +80,3 @@ namespace boot
}
};
}
}

View File

@ -24,9 +24,7 @@ along with GCC; see the file COPYING3. If not see
#include "elna/boot/result.h"
#include "elna/boot/symbol.h"
namespace elna
{
namespace boot
namespace elna::boot
{
class undeclared_error : public error
{
@ -68,4 +66,3 @@ namespace boot
void visit(procedure_type_expression *) override;
};
}
}

View File

@ -23,9 +23,7 @@ along with GCC; see the file COPYING3. If not see
#include <memory>
#include <vector>
namespace elna
{
namespace boot
namespace elna::boot
{
class alias_type;
class primitive_type;
@ -257,4 +255,3 @@ namespace boot
std::shared_ptr<symbol_table> builtin_symbol_table();
}
}

View File

@ -25,11 +25,8 @@ along with GCC; see the file COPYING3. If not see
#include "elna/gcc/elna-tree.h"
namespace elna
{
namespace gcc
namespace elna::gcc
{
void init_ttree();
std::shared_ptr<symbol_table> builtin_symbol_table();
}
}

View File

@ -29,12 +29,9 @@ along with GCC; see the file COPYING3. If not see
#include "elna/boot/result.h"
namespace elna
{
namespace gcc
namespace elna::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);
}
}

View File

@ -30,9 +30,7 @@ along with GCC; see the file COPYING3. If not see
#include <string>
namespace elna
{
namespace gcc
namespace elna::gcc
{
std::deque<std::unique_ptr<boot::error>> do_semantic_analysis(const char *path,
std::unique_ptr<boot::program>& ast, std::shared_ptr<boot::symbol_table> info_table,
@ -74,13 +72,13 @@ namespace gcc
void visit(boot::procedure_call *call) override;
void visit(boot::cast_expression *expression) override;
void visit(boot::traits_expression *trait) override;
void visit(boot::number_literal<std::int32_t> *literal) override;
void visit(boot::number_literal<std::uint32_t> *literal) override;
void visit(boot::number_literal<double> *literal) override;
void visit(boot::number_literal<bool> *boolean) override;
void visit(boot::number_literal<unsigned char> *character) override;
void visit(boot::number_literal<std::nullptr_t> *) override;
void visit(boot::number_literal<std::string> *string) override;
void visit(boot::literal<std::int32_t> *literal) override;
void visit(boot::literal<std::uint32_t> *literal) override;
void visit(boot::literal<double> *literal) override;
void visit(boot::literal<bool> *boolean) override;
void visit(boot::literal<unsigned char> *character) override;
void visit(boot::literal<std::nullptr_t> *) override;
void visit(boot::literal<std::string> *string) override;
void visit(boot::binary_expression *expression) override;
void visit(boot::unary_expression *expression) override;
void visit(boot::constant_definition *definition) override;
@ -104,4 +102,3 @@ namespace gcc
void visit(boot::defer_statement *statement) override;
};
}
}

View File

@ -29,9 +29,7 @@ along with GCC; see the file COPYING3. If not see
#include "elna/boot/ast.h"
#include "elna/boot/symbol.h"
namespace elna
{
namespace gcc
namespace elna::gcc
{
using symbol_table = boot::symbol_map<tree, tree, NULL_TREE>;
@ -82,4 +80,3 @@ namespace gcc
tree_code operator_code, tree left, tree right);
tree build_field(location_t location, tree record_type, const std::string name, tree type);
}
}