diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-07-19 17:09:40 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-07-19 18:30:21 +0200 |
| commit | cdbc1695a93910df5729779de31912a3b4b4172b (patch) | |
| tree | 43a4c5a192df7060f8a36c75d339be7ac5722f72 /include | |
| parent | cd2ee0c97348444779a155909b7ec78d89cfd2e0 (diff) | |
| download | elna-cdbc1695a93910df5729779de31912a3b4b4172b.tar.gz | |
Support unary plus operation
Diffstat (limited to 'include')
| -rw-r--r-- | include/elna/boot/ast.h | 3 | ||||
| -rw-r--r-- | include/elna/boot/symbol.h | 28 | ||||
| -rw-r--r-- | include/elna/boot/type_check.h | 18 |
3 files changed, 48 insertions, 1 deletions
diff --git a/include/elna/boot/ast.h b/include/elna/boot/ast.h index 9d978a3..30bc7c3 100644 --- a/include/elna/boot/ast.h +++ b/include/elna/boot/ast.h @@ -51,7 +51,8 @@ namespace elna::boot { reference, negation, - minus + minus, + plus }; class variable_declaration; diff --git a/include/elna/boot/symbol.h b/include/elna/boot/symbol.h index 216021e..194c1cd 100644 --- a/include/elna/boot/symbol.h +++ b/include/elna/boot/symbol.h @@ -475,6 +475,34 @@ namespace elna::boot bool is_primitive_type(const type& checked, const std::string& name); /** + * Checks whether the given type is a numeric primitive type + * (\c Int, \c Word, or \c Float). + * + * \param checked The type to check. + * \return Whether the type is a numeric primitive. + */ + bool is_numeric_type(const type& checked); + + /** + * Checks whether the given type is an integral primitive type + * (\c Int or \c Word). + * + * \param checked The type to check. + * \return Whether the type is an integral primitive. + */ + bool is_integral_type(const type& checked); + + /** + * Checks whether the given type is a discrete primitive type + * (\c Int, \c Word, \c Bool, or \c Char), i.e. a type with a + * finite range of ordered values suitable for \c \#min/\c \#max. + * + * \param checked The type to check. + * \return Whether the type is a discrete primitive. + */ + bool is_discrete_type(const type& checked); + + /** * Checks whether the given type is a pointer type. * * A pointer type is considered to be a variable pointer, a procedure diff --git a/include/elna/boot/type_check.h b/include/elna/boot/type_check.h index 5b6ed1c..8c7dd80 100644 --- a/include/elna/boot/type_check.h +++ b/include/elna/boot/type_check.h @@ -175,6 +175,23 @@ namespace elna::boot }; /** + * A unary operator is applied to an unsupported type. + */ + class unary_operation_error : public error + { + type actual; + unary_operator op; + + static char unary_operator_symbol(unary_operator op); + + public: + unary_operation_error(const source_position position, type actual, + unary_operator op); + + std::string what() const override; + }; + + /** * Chain of responsibility for type compatibility checks. * * Populate \c ctx with pre-resolved types, then call \c run(). @@ -237,5 +254,6 @@ namespace elna::boot void visit(case_statement *statement) override; void visit(record_constructor_expression *expression) override; void visit(array_constructor_expression *expression) override; + void visit(unary_expression *expression) override; }; } |
