this->unget_token(Token::make_identifier_token(identifier, is_exported,
location));
}
+ else if (p_range_clause != NULL && token->is_keyword(KEYWORD_RANGE))
+ {
+ Typed_identifier_list til;
+ this->range_clause_decl(&til, p_range_clause);
+ return NULL;
+ }
Expression* exp = this->expression(PRECEDENCE_NORMAL, true,
may_be_composite_lit,
}
}
-// RangeClause = IdentifierList ( "=" | ":=" ) "range" Expression .
+// RangeClause = [ IdentifierList ( "=" | ":=" ) ] "range" Expression .
// This is the := version. It is called with a list of identifiers.
p_range_clause->found = true;
- go_assert(til->size() >= 1);
if (til->size() > 2)
error_at(this->location(), "too many variables for range clause");
NULL);
p_range_clause->range = expr;
+ if (til->empty())
+ return;
+
bool any_new = false;
const Typed_identifier* pti = &til->front();
p_range_clause->range = this->expression(PRECEDENCE_NORMAL, false, false,
NULL, NULL);
+ if (vals->empty())
+ return;
+
p_range_clause->index = vals->front();
if (vals->size() == 1)
p_range_clause->value = NULL;
int
For_range_statement::do_traverse(Traverse* traverse)
{
- if (this->traverse_expression(traverse, &this->index_var_) == TRAVERSE_EXIT)
- return TRAVERSE_EXIT;
+ if (this->index_var_ != NULL)
+ {
+ if (this->traverse_expression(traverse, &this->index_var_)
+ == TRAVERSE_EXIT)
+ return TRAVERSE_EXIT;
+ }
if (this->value_var_ != NULL)
{
if (this->traverse_expression(traverse, &this->value_var_)
if (iter_init != NULL)
body->add_statement(Statement::make_block_statement(iter_init, loc));
- Statement* assign;
- Expression* index_ref = Expression::make_temporary_reference(index_temp, loc);
- if (this->value_var_ == NULL)
+ if (this->index_var_ != NULL)
{
- assign = Statement::make_assignment(this->index_var_, index_ref, loc);
- }
- else
- {
- Expression_list* lhs = new Expression_list();
- lhs->push_back(this->index_var_);
- lhs->push_back(this->value_var_);
+ Statement* assign;
+ Expression* index_ref =
+ Expression::make_temporary_reference(index_temp, loc);
+ if (this->value_var_ == NULL)
+ assign = Statement::make_assignment(this->index_var_, index_ref, loc);
+ else
+ {
+ Expression_list* lhs = new Expression_list();
+ lhs->push_back(this->index_var_);
+ lhs->push_back(this->value_var_);
- Expression_list* rhs = new Expression_list();
- rhs->push_back(index_ref);
- rhs->push_back(Expression::make_temporary_reference(value_temp, loc));
+ Expression_list* rhs = new Expression_list();
+ rhs->push_back(index_ref);
+ rhs->push_back(Expression::make_temporary_reference(value_temp, loc));
- assign = Statement::make_tuple_assignment(lhs, rhs, loc);
+ assign = Statement::make_tuple_assignment(lhs, rhs, loc);
+ }
+ body->add_statement(assign);
}
- body->add_statement(assign);
body->add_statement(Statement::make_block_statement(this->statements_, loc));