if ((*plhs)->is_sink_expression())
{
- b->add_statement(Statement::make_statement(*prhs));
+ b->add_statement(Statement::make_statement(*prhs, true));
continue;
}
Expression* p4 = Expression::make_temporary_reference(insert_temp, loc);
Expression* call = Runtime::make_call(Runtime::MAPASSIGN2, loc, 4,
p1, p2, p3, p4);
- Statement* s = Statement::make_statement(call);
+ Statement* s = Statement::make_statement(call, true);
b->add_statement(s);
return Statement::make_block_statement(b, loc);
class Expression_statement : public Statement
{
public:
- Expression_statement(Expression* expr)
+ Expression_statement(Expression* expr, bool is_ignored)
: Statement(STATEMENT_EXPRESSION, expr->location()),
- expr_(expr)
+ expr_(expr), is_ignored_(is_ignored)
{ }
Expression*
do_determine_types()
{ this->expr_->determine_type_no_context(); }
+ void
+ do_check_types(Gogo*);
+
bool
do_may_fall_through() const;
private:
Expression* expr_;
+ // Whether the value of this expression is being explicitly ignored.
+ bool is_ignored_;
};
+// Check the types of an expression statement. The only check we do
+// is to possibly give an error about discarding the value of the
+// expression.
+
+void
+Expression_statement::do_check_types(Gogo*)
+{
+ if (!this->is_ignored_)
+ this->expr_->discarding_value();
+}
+
// An expression statement may fall through unless it is a call to a
// function which does not return.
// Make an expression statement from an Expression.
Statement*
-Statement::make_statement(Expression* expr)
+Statement::make_statement(Expression* expr, bool is_ignored)
{
- return new Expression_statement(expr);
+ return new Expression_statement(expr, is_ignored);
}
// A block statement--a list of statements which may include variable
// receiver parameter.
call->set_varargs_are_lowered();
- Statement* call_statement = Statement::make_statement(call);
+ Statement* call_statement = Statement::make_statement(call, true);
gogo->add_statement(call_statement);
Expression* val = this->val_;
if (val == NULL)
val = Expression::make_boolean(true, loc);
- return Statement::make_statement(val);
+ return Statement::make_statement(val, true);
}
Temporary_statement* val_temp;
}
else
{
- init->add_statement(Statement::make_statement(recv));
+ init->add_statement(Statement::make_statement(recv, true));
}
}
Expression* ref = Expression::make_temporary_reference(hiter, loc);
Expression* p2 = Expression::make_unary(OPERATOR_AND, ref, loc);
Expression* call = Runtime::make_call(Runtime::MAPITERINIT, loc, 2, p1, p2);
- init->add_statement(Statement::make_statement(call));
+ init->add_statement(Statement::make_statement(call, true));
*pinit = init;
Expression* p3 = Expression::make_unary(OPERATOR_AND, ref, loc);
call = Runtime::make_call(Runtime::MAPITER2, loc, 3, p1, p2, p3);
}
- iter_init->add_statement(Statement::make_statement(call));
+ iter_init->add_statement(Statement::make_statement(call, true));
*piter_init = iter_init;
ref = Expression::make_temporary_reference(hiter, loc);
p1 = Expression::make_unary(OPERATOR_AND, ref, loc);
call = Runtime::make_call(Runtime::MAPITERNEXT, loc, 1, p1);
- post->add_statement(Statement::make_statement(call));
+ post->add_statement(Statement::make_statement(call, true));
*ppost = post;
}