Skip parameter names in procedure type expressions
This commit is contained in:
@ -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,53 +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;
|
||||
};
|
||||
|
||||
/**
|
||||
* A visitor which visits all nodes but does nothing.
|
||||
*/
|
||||
struct empty_visitor : parser_visitor
|
||||
{
|
||||
virtual void visit(variable_declaration *) override;
|
||||
virtual void visit(constant_definition *) override;
|
||||
virtual void visit(procedure_definition *) override;
|
||||
virtual void visit(type_definition *) override;
|
||||
virtual void visit(procedure_call *) override;
|
||||
virtual void visit(cast_expression *) override;
|
||||
virtual void visit(traits_expression *) override;
|
||||
virtual void visit(assign_statement *) override;
|
||||
virtual void visit(if_statement *) override;
|
||||
virtual void visit(while_statement *) override;
|
||||
virtual void visit(return_statement *) override;
|
||||
virtual void visit(defer_statement *) override;
|
||||
virtual void visit(block *) override;
|
||||
virtual void visit(program *) override;
|
||||
virtual void visit(binary_expression *) override;
|
||||
virtual void visit(unary_expression *) override;
|
||||
virtual void visit(primitive_type_expression *) override;
|
||||
virtual void visit(array_type_expression *) override;
|
||||
virtual void visit(pointer_type_expression *) override;
|
||||
virtual void visit(record_type_expression *) override;
|
||||
virtual void visit(union_type_expression *) override;
|
||||
virtual void visit(procedure_type_expression *) override;
|
||||
virtual void visit(variable_expression *) override;
|
||||
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> *) = 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;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -213,7 +172,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 +295,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 +318,7 @@ namespace boot
|
||||
*/
|
||||
class constant_definition : public definition
|
||||
{
|
||||
literal *m_body;
|
||||
literal_expression *m_body;
|
||||
|
||||
public:
|
||||
/**
|
||||
@ -368,10 +327,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 +338,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 +354,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 +373,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);
|
||||
@ -459,17 +420,13 @@ namespace boot
|
||||
|
||||
class traits_expression : public expression
|
||||
{
|
||||
std::shared_ptr<type_expression> m_type;
|
||||
|
||||
public:
|
||||
std::vector<std::shared_ptr<type_expression>> parameters;
|
||||
const std::string name;
|
||||
|
||||
traits_expression(const struct position position, const std::string& name,
|
||||
std::shared_ptr<type_expression> type);
|
||||
traits_expression(const struct position position, const std::string& name);
|
||||
void accept(parser_visitor *visitor);
|
||||
traits_expression *is_traits() override;
|
||||
|
||||
type_expression& type();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -688,21 +645,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 +667,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 +679,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 +691,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 +703,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 +715,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 +727,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 +797,3 @@ namespace boot
|
||||
|
||||
const char *print_binary_operator(const binary_operator operation);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
@ -48,7 +46,7 @@ namespace boot
|
||||
std::string what() const override;
|
||||
};
|
||||
|
||||
class declaration_visitor final : public empty_visitor, public error_container
|
||||
class declaration_visitor final : public parser_visitor, public error_container
|
||||
{
|
||||
type current_type;
|
||||
std::shared_ptr<symbol_table> symbols;
|
||||
@ -66,6 +64,31 @@ namespace boot
|
||||
void visit(record_type_expression *) override;
|
||||
void visit(union_type_expression *) override;
|
||||
void visit(procedure_type_expression *) override;
|
||||
|
||||
void visit(variable_declaration *) override;
|
||||
void visit(constant_definition *) override;
|
||||
void visit(procedure_definition *) override;
|
||||
void visit(assign_statement *) override;
|
||||
void visit(if_statement *) override;
|
||||
void visit(while_statement *) override;
|
||||
void visit(return_statement *) override;
|
||||
void visit(defer_statement *) override;
|
||||
void visit(procedure_call *) override;
|
||||
void visit(block *) override;
|
||||
void visit(cast_expression *) override;
|
||||
void visit(traits_expression *) override;
|
||||
void visit(binary_expression *) override;
|
||||
void visit(unary_expression *) override;
|
||||
void visit(variable_expression *) override;
|
||||
void visit(array_access_expression *) override;
|
||||
void visit(field_access_expression *) override;
|
||||
void visit(dereference_expression *) override;
|
||||
void visit(literal<std::int32_t> *) override;
|
||||
void visit(literal<std::uint32_t> *) override;
|
||||
void visit(literal<double> *) override;
|
||||
void visit(literal<bool> *) override;
|
||||
void visit(literal<unsigned char> *) override;
|
||||
void visit(literal<std::nullptr_t> *) override;
|
||||
void visit(literal<std::string> *) override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -30,16 +30,14 @@ 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,
|
||||
std::shared_ptr<symbol_table> symbols);
|
||||
tree handle_symbol(const std::string& symbol_name, const boot::type& type, std::shared_ptr<symbol_table> symbols);
|
||||
|
||||
class generic_visitor final : public boot::empty_visitor
|
||||
class generic_visitor final : public boot::parser_visitor
|
||||
{
|
||||
tree current_expression{ NULL_TREE };
|
||||
std::shared_ptr<symbol_table> symbols;
|
||||
@ -64,6 +62,9 @@ namespace gcc
|
||||
tree procedure_address, const std::vector<boot::expression *>& arguments);
|
||||
void build_record_call(location_t call_location,
|
||||
tree symbol, const std::vector<boot::expression *>& arguments);
|
||||
|
||||
bool expect_trait_type_only(boot::traits_expression *trait);
|
||||
bool expect_trait_for_integral_type(boot::traits_expression *trait);
|
||||
void visit_statements(const std::vector<boot::statement *>& statements);
|
||||
|
||||
public:
|
||||
@ -74,13 +75,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 +105,3 @@ namespace gcc
|
||||
void visit(boot::defer_statement *statement) override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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>;
|
||||
|
||||
@ -81,5 +79,5 @@ namespace gcc
|
||||
tree build_arithmetic_operation(boot::binary_expression *expression,
|
||||
tree_code operator_code, tree left, tree right);
|
||||
tree build_field(location_t location, tree record_type, const std::string name, tree type);
|
||||
}
|
||||
tree find_field_by_name(location_t expression_location, tree type, const std::string& field_name);
|
||||
}
|
||||
|
Reference in New Issue
Block a user