Skip to content
Snippets Groups Projects
Commit a66ba048 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Fix R^d component affectation

parent 8366faeb
No related branches found
No related tags found
1 merge request!37Feature/language
...@@ -137,8 +137,8 @@ class ComponentAffectationExecutor final : public IAffectationExecutor ...@@ -137,8 +137,8 @@ class ComponentAffectationExecutor final : public IAffectationExecutor
}()}; }()};
public: public:
ComponentAffectationExecutor(ASTNode& node, ArrayT& lhs_array) ComponentAffectationExecutor(ASTNode& node, ArrayT& lhs_array, ASTNode& index_expression)
: m_lhs_array{lhs_array}, m_index_expression{*node.children[1]} : m_lhs_array{lhs_array}, m_index_expression{index_expression}
{ {
// LCOV_EXCL_START // LCOV_EXCL_START
if constexpr (not _is_defined) { if constexpr (not _is_defined) {
...@@ -235,14 +235,17 @@ class AffectationProcessor final : public INodeProcessor ...@@ -235,14 +235,17 @@ class AffectationProcessor final : public INodeProcessor
const std::string& symbol = array_expression.string(); const std::string& symbol = array_expression.string();
auto [i_symbol, found] = m_node.m_symbol_table->find(symbol, m_node.children[0]->begin()); auto [i_symbol, found] = m_node.m_symbol_table->find(symbol, array_subscript_expression.begin());
Assert(found); Assert(found);
DataVariant& value = i_symbol->attributes().value(); DataVariant& value = i_symbol->attributes().value();
if (array_expression.m_data_type != ASTNodeDataType::vector_t) { if (array_expression.m_data_type != ASTNodeDataType::vector_t) {
throw parse_error("unexpected error: invalid lhs (expecting R^d)", std::vector{node.children[0]->begin()}); throw parse_error("unexpected error: invalid lhs (expecting R^d)",
std::vector{array_subscript_expression.begin()});
} }
auto& index_expression = *array_subscript_expression.children[1];
switch (array_expression.m_data_type.dimension()) { switch (array_expression.m_data_type.dimension()) {
case 1: { case 1: {
using ArrayTypeT = TinyVector<1>; using ArrayTypeT = TinyVector<1>;
...@@ -250,7 +253,8 @@ class AffectationProcessor final : public INodeProcessor ...@@ -250,7 +253,8 @@ class AffectationProcessor final : public INodeProcessor
value = ArrayTypeT{}; value = ArrayTypeT{};
} }
using AffectationExecutorT = ComponentAffectationExecutor<OperatorT, ArrayTypeT, ValueT, DataT>; using AffectationExecutorT = ComponentAffectationExecutor<OperatorT, ArrayTypeT, ValueT, DataT>;
m_affectation_executor = std::make_unique<AffectationExecutorT>(m_node, std::get<ArrayTypeT>(value)); m_affectation_executor =
std::make_unique<AffectationExecutorT>(node, std::get<ArrayTypeT>(value), index_expression);
break; break;
} }
case 2: { case 2: {
...@@ -259,7 +263,8 @@ class AffectationProcessor final : public INodeProcessor ...@@ -259,7 +263,8 @@ class AffectationProcessor final : public INodeProcessor
value = ArrayTypeT{}; value = ArrayTypeT{};
} }
using AffectationExecutorT = ComponentAffectationExecutor<OperatorT, ArrayTypeT, ValueT, DataT>; using AffectationExecutorT = ComponentAffectationExecutor<OperatorT, ArrayTypeT, ValueT, DataT>;
m_affectation_executor = std::make_unique<AffectationExecutorT>(m_node, std::get<ArrayTypeT>(value)); m_affectation_executor =
std::make_unique<AffectationExecutorT>(node, std::get<ArrayTypeT>(value), index_expression);
break; break;
} }
case 3: { case 3: {
...@@ -268,11 +273,13 @@ class AffectationProcessor final : public INodeProcessor ...@@ -268,11 +273,13 @@ class AffectationProcessor final : public INodeProcessor
value = ArrayTypeT{}; value = ArrayTypeT{};
} }
using AffectationExecutorT = ComponentAffectationExecutor<OperatorT, ArrayTypeT, ValueT, DataT>; using AffectationExecutorT = ComponentAffectationExecutor<OperatorT, ArrayTypeT, ValueT, DataT>;
m_affectation_executor = std::make_unique<AffectationExecutorT>(m_node, std::get<ArrayTypeT>(value)); m_affectation_executor =
std::make_unique<AffectationExecutorT>(node, std::get<ArrayTypeT>(value), index_expression);
break; break;
} }
default: { default: {
throw parse_error("unexpected error: invalid vector dimension", std::vector{node.children[0]->begin()}); throw parse_error("unexpected error: invalid vector dimension",
std::vector{array_subscript_expression.begin()});
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment