diff --git a/TODO b/TODO index 3c102fc..7f0f484 100644 --- a/TODO +++ b/TODO @@ -3,7 +3,6 @@ - Catch exceptions thrown by the argument parser and print them normally. - Structs or records. - Unions. -- Type checking. - Support immediates greater than 12 bits. - It seems instructions are correctly encoded only if the compiler is running on a little endian architecture. @@ -13,5 +12,3 @@ - Error message with an empty file wrongly says that a ")" is expected. - Support any expressions for constants. - Name analysis should fail if there are undefined symbols. -- type_mismatch error should get second type argument for the - expected type. diff --git a/include/elna/source/result.hpp b/include/elna/source/result.hpp index a67fcab..b75a38e 100644 --- a/include/elna/source/result.hpp +++ b/include/elna/source/result.hpp @@ -137,7 +137,8 @@ namespace elna::source argument, arithmetic, comparison, - condition + condition, + assignment }; /** diff --git a/include/elna/source/semantic.hpp b/include/elna/source/semantic.hpp index 2bda336..55c7433 100644 --- a/include/elna/source/semantic.hpp +++ b/include/elna/source/semantic.hpp @@ -88,5 +88,6 @@ namespace elna::source void visit(constant_definition *definition) override; void visit(while_statement *statement) override; void visit(if_statement *statement) override; + void visit(assign_statement *statement) override; }; } diff --git a/source/semantic.cpp b/source/semantic.cpp index 0a50ec7..789fd48 100644 --- a/source/semantic.cpp +++ b/source/semantic.cpp @@ -305,6 +305,19 @@ namespace elna::source statement->body().accept(this); } + void type_analysis_visitor::visit(assign_statement *statement) + { + statement->rvalue().accept(this); + auto lvalue_info = std::dynamic_pointer_cast(this->table->lookup(statement->lvalue())); + + if (statement->rvalue().data_type != nullptr && lvalue_info->type() == statement->rvalue().data_type) + { + auto new_error = std::make_unique(statement->rvalue().data_type, + type_mismatch::operation::assignment, this->filename, statement->position()); + m_errors.push_back(std::move(new_error)); + } + } + const std::list>& type_analysis_visitor::errors() const noexcept { return m_errors;