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

Allow tuple affectations

``
R x=0;
R y=3;
(x,y) += (3,2);
``
parent 9e17aa66
No related branches found
No related tags found
1 merge request!37Feature/language
......@@ -8,7 +8,7 @@ void
ASTSymbolInitializationChecker::_checkSymbolInitialization(ASTNode& node)
{
if (node.is_type<language::declaration>()) {
auto set_is_initialized = [&](ASTNode& name_node) {
auto check_if_initialized = [&](ASTNode& name_node) {
const std::string& symbol = name_node.string();
auto [i_symbol, found] = node.m_symbol_table->find(symbol, name_node.begin());
Assert(found, "unexpected error, should have been detected through declaration checking");
......@@ -19,11 +19,11 @@ ASTSymbolInitializationChecker::_checkSymbolInitialization(ASTNode& node)
};
if (node.children[1]->is_type<language::name>()) {
set_is_initialized(*node.children[1]);
check_if_initialized(*node.children[1]);
} else if (node.children[1]->is_type<language::name_list>()) {
ASTNode& name_list_node = *node.children[1];
for (auto& child_node : name_list_node.children) {
set_is_initialized(*child_node);
check_if_initialized(*child_node);
}
}
} else if (node.is_type<language::let_declaration>()) {
......@@ -44,11 +44,22 @@ ASTSymbolInitializationChecker::_checkSymbolInitialization(ASTNode& node)
} else if (node.is_type<language::eq_op>()) {
// first checks for right hand side
this->_checkSymbolInitialization(*node.children[1]);
// then marks left hand side as initialized
const std::string& symbol = node.children[0]->string();
auto [i_symbol, found] = node.m_symbol_table->find(symbol, node.children[0]->begin());
auto set_is_initialized = [&](ASTNode& name_node) {
const std::string& symbol = name_node.string();
auto [i_symbol, found] = node.m_symbol_table->find(symbol, name_node.begin());
Assert(found, "unexpected error, should have been detected through declaration checking");
i_symbol->attributes().setIsInitialized();
};
if (node.children[0]->is_type<language::name>()) {
set_is_initialized(*node.children[0]);
} else if (node.children[0]->is_type<language::name_list>()) {
ASTNode& name_list_node = *node.children[0];
for (auto& child_node : name_list_node.children) {
set_is_initialized(*child_node);
}
}
} else if (node.is_type<language::name>()) {
auto [i_symbol, found] = node.m_symbol_table->find(node.string(), node.begin());
Assert(found, "unexpected error, should have been detected through declaration checking");
......
......@@ -211,9 +211,10 @@ struct expression_list : seq< open_parent, expression, plus< if_must< COMMA, exp
struct affect_op : sor< eq_op, multiplyeq_op, divideeq_op, pluseq_op, minuseq_op > {};
struct affectation : seq< NAME , if_must< affect_op, sor< expression_list, expression > > >{};
struct name_list;
struct affectation : seq< sor< NAME, name_list >, if_must< affect_op, sor< expression_list, expression > > >{};
struct declaration : if_must< type_expression, sor< NAME, name_list>, opt< if_must< seq< one< '=' >, ignored >, sor< expression_list, expression > > > >{};
struct type_mapping : seq< type_expression, RIGHT_ARROW, type_expression >{};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment