aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-08-14 17:22:17 +0200
committerEugen Wissner <belka@caraus.de>2026-08-14 17:22:17 +0200
commitd696abc97143061bf2abb05922188e12b59306c1 (patch)
treedf8d2d1799e7036566d02e2201d159634d576481 /include
parentbf7416a3ef9f0b787dcaebf816f3f3e6e385ff42 (diff)
downloadelna-d696abc97143061bf2abb05922188e12b59306c1.tar.gz
Use the new .is_a() for literal kind checks in the evaluator
Diffstat (limited to 'include')
-rw-r--r--include/elna/boot/name_analysis.h4
-rw-r--r--include/elna/boot/result.h13
-rw-r--r--include/elna/boot/type_check.h58
-rw-r--r--include/elna/boot/validation.h10
4 files changed, 58 insertions, 27 deletions
diff --git a/include/elna/boot/name_analysis.h b/include/elna/boot/name_analysis.h
index 9e10fab..a9e7f24 100644
--- a/include/elna/boot/name_analysis.h
+++ b/include/elna/boot/name_analysis.h
@@ -63,7 +63,7 @@ namespace elna::boot
* \c const qualifier used incorrectly — wrong position or
* duplicate.
*/
- class name_analysis_error final : public error
+ class const_qualifier_error final : public error
{
public:
enum class kind
@@ -77,7 +77,7 @@ namespace elna::boot
};
using payload_type = std::variant<not_initialized, kind>;
- name_analysis_error(const source_position position, payload_type payload);
+ const_qualifier_error(const source_position position, payload_type payload);
std::optional<std::pair<std::string, source_position>> note() const override;
std::string what() const override;
diff --git a/include/elna/boot/result.h b/include/elna/boot/result.h
index 03d589e..bf2149a 100644
--- a/include/elna/boot/result.h
+++ b/include/elna/boot/result.h
@@ -184,6 +184,19 @@ namespace elna::boot
};
/**
+ * Creates an error note pointing to a previous declaration.
+ *
+ * \param original Source position of the previous declaration.
+ * \param label Description what was declared previously.
+ * \return Error note if the position of the previous declaration is available.
+ */
+ std::optional<std::pair<std::string, source_position>> previous_declaration_note(
+ const std::optional<source_position>& original, std::string_view label = "previously declared here");
+
+ std::optional<std::pair<std::string, source_position>> identifier_list_note(
+ const std::vector<identifier>& identifiers);
+
+ /**
* Checks whether the givn object can be converted to a string using
* the .to_string() method.
*/
diff --git a/include/elna/boot/type_check.h b/include/elna/boot/type_check.h
index 93e891a..52eec61 100644
--- a/include/elna/boot/type_check.h
+++ b/include/elna/boot/type_check.h
@@ -58,14 +58,8 @@ namespace elna::boot
{
integer_literal overflow;
};
- enum class kind {
- record_base,
- for_range,
- condition,
- constant_assignment,
- array_index,
- non_indexable,
- dereference_of_non_pointer
+ struct constant_assignment
+ {
};
using payload_type = std::variant<
expected_type,
@@ -74,7 +68,7 @@ namespace elna::boot
binary,
invalid_cast,
integer_literal_overflow,
- kind
+ constant_assignment
>;
type_mismatch_error(const source_position position,
@@ -87,6 +81,29 @@ namespace elna::boot
payload_type payload;
};
+ class type_requirement_error : public error
+ {
+ public:
+ enum class kind
+ {
+ record_base,
+ for_range,
+ condition,
+ array_index,
+ non_indexable,
+ dereference_of_non_pointer
+ };
+
+ type_requirement_error(const source_position position,
+ type actual, kind kind);
+
+ std::string what() const override;
+
+ private:
+ type actual;
+ kind m_kind;
+ };
+
/**
* Cyclic type declaration.
*/
@@ -95,7 +112,7 @@ namespace elna::boot
std::vector<std::string> cycle;
public:
- cyclic_declaration_error(const std::vector<std::string>& cycle, const source_position position);
+ cyclic_declaration_error(const source_position position, const std::vector<std::string>& cycle);
std::string what() const override;
};
@@ -106,12 +123,22 @@ namespace elna::boot
*/
class argument_count_error final : public error
{
+ public:
+ enum class kind
+ {
+ trait,
+ call,
+ array
+ };
+ private:
+ kind m_kind;
+ std::string applicand;
std::size_t expected;
std::size_t actual;
public:
- argument_count_error(std::size_t expected, std::size_t actual,
- const source_position position);
+ argument_count_error(const source_position position, kind kind,
+ std::string applicand, std::size_t expected, std::size_t actual);
std::string what() const override;
};
@@ -122,18 +149,15 @@ namespace elna::boot
class trait_error final : public error
{
public:
- struct argument_count
+ struct offset_not_field_name
{
- std::size_t expected;
- std::size_t actual;
};
- struct offset_not_field_name {};
struct unsupported_type
{
type actual;
};
- using payload_type = std::variant<argument_count, offset_not_field_name, unsupported_type>;
+ using payload_type = std::variant<offset_not_field_name, unsupported_type>;
trait_error(const source_position position, const std::string& trait_name,
payload_type payload);
diff --git a/include/elna/boot/validation.h b/include/elna/boot/validation.h
index 171ac1d..65972b7 100644
--- a/include/elna/boot/validation.h
+++ b/include/elna/boot/validation.h
@@ -30,19 +30,13 @@ namespace elna::boot
class validation_error final : public error
{
public:
- struct duplicate_case
- {
- source_position first;
- };
- using payload_type = std::variant<duplicate_case>;
-
- validation_error(const source_position position, payload_type payload);
+ validation_error(const source_position position, source_position first);
std::string what() const override;
std::optional<std::pair<std::string, source_position>> note() const override;
private:
- payload_type payload;
+ source_position first;
};
/**