aboutsummaryrefslogtreecommitdiff
path: root/gcc/go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-03-24 00:40:21 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-03-24 00:40:21 +0000
commitfd68e6ba7254ebe7feeeafe1fd6686b2ada8eeff (patch)
tree91ab079953ca16f0b2e9827450815c431130b628 /gcc/go
parent5278672ca11d7be0cd93f224689f78687adb91ed (diff)
downloadgcc-fd68e6ba7254ebe7feeeafe1fd6686b2ada8eeff.zip
gcc-fd68e6ba7254ebe7feeeafe1fd6686b2ada8eeff.tar.gz
gcc-fd68e6ba7254ebe7feeeafe1fd6686b2ada8eeff.tar.bz2
Condition in if statement is not optional.
From-SVN: r171377
Diffstat (limited to 'gcc/go')
-rw-r--r--gcc/go/gofrontend/parse.cc6
-rw-r--r--gcc/go/gofrontend/statements.cc35
2 files changed, 13 insertions, 28 deletions
diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc
index 2e59149..e658899 100644
--- a/gcc/go/gofrontend/parse.cc
+++ b/gcc/go/gofrontend/parse.cc
@@ -3703,8 +3703,7 @@ Parse::return_stat()
location));
}
-// IfStat = "if" [ [ SimpleStat ] ";" ] [ Condition ]
-// Block [ "else" Statement ] .
+// IfStmt = "if" [ SimpleStmt ";" ] Expression Block [ "else" Statement ] .
void
Parse::if_stat()
@@ -3728,8 +3727,7 @@ Parse::if_stat()
{
if (this->peek_token()->is_op(OPERATOR_SEMICOLON))
this->advance_token();
- if (!this->peek_token()->is_op(OPERATOR_LCURLY))
- cond = this->expression(PRECEDENCE_NORMAL, false, false, NULL);
+ cond = this->expression(PRECEDENCE_NORMAL, false, false, NULL);
}
this->gogo_->start_block(this->location());
diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc
index 5a4ad06..0a6ef8c 100644
--- a/gcc/go/gofrontend/statements.cc
+++ b/gcc/go/gofrontend/statements.cc
@@ -2956,12 +2956,8 @@ class If_statement : public Statement
int
If_statement::do_traverse(Traverse* traverse)
{
- if (this->cond_ != NULL)
- {
- if (this->traverse_expression(traverse, &this->cond_) == TRAVERSE_EXIT)
- return TRAVERSE_EXIT;
- }
- if (this->then_block_->traverse(traverse) == TRAVERSE_EXIT)
+ if (this->traverse_expression(traverse, &this->cond_) == TRAVERSE_EXIT
+ || this->then_block_->traverse(traverse) == TRAVERSE_EXIT)
return TRAVERSE_EXIT;
if (this->else_block_ != NULL)
{
@@ -2974,11 +2970,8 @@ If_statement::do_traverse(Traverse* traverse)
void
If_statement::do_determine_types()
{
- if (this->cond_ != NULL)
- {
- Type_context context(Type::lookup_bool_type(), false);
- this->cond_->determine_type(&context);
- }
+ Type_context context(Type::lookup_bool_type(), false);
+ this->cond_->determine_type(&context);
this->then_block_->determine_types();
if (this->else_block_ != NULL)
this->else_block_->determine_types();
@@ -2989,14 +2982,11 @@ If_statement::do_determine_types()
void
If_statement::do_check_types(Gogo*)
{
- if (this->cond_ != NULL)
- {
- Type* type = this->cond_->type();
- if (type->is_error_type())
- this->set_is_error();
- else if (!type->is_boolean_type())
- this->report_error(_("expected boolean expression"));
- }
+ Type* type = this->cond_->type();
+ if (type->is_error_type())
+ this->set_is_error();
+ else if (!type->is_boolean_type())
+ this->report_error(_("expected boolean expression"));
}
// Whether the overall statement may fall through.
@@ -3014,12 +3004,9 @@ If_statement::do_may_fall_through() const
tree
If_statement::do_get_tree(Translate_context* context)
{
- gcc_assert(this->cond_ == NULL
- || this->cond_->type()->is_boolean_type()
+ gcc_assert(this->cond_->type()->is_boolean_type()
|| this->cond_->type()->is_error_type());
- tree cond_tree = (this->cond_ == NULL
- ? boolean_true_node
- : this->cond_->get_tree(context));
+ tree cond_tree = this->cond_->get_tree(context);
tree then_tree = this->then_block_->get_tree(context);
tree else_tree = (this->else_block_ == NULL
? NULL_TREE