aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/expressions.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/go/gofrontend/expressions.cc')
-rw-r--r--gcc/go/gofrontend/expressions.cc105
1 files changed, 105 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index d82eebd..740daec 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -7110,6 +7110,12 @@ Binary_expression::do_import(Import_expression* imp, Location loc)
op = OPERATOR_BITCLEAR;
imp->advance(4);
}
+ else if (imp->match_c_string(")"))
+ {
+ // Not a binary operator after all.
+ imp->advance(1);
+ return left;
+ }
else
{
go_error_at(imp->location(), "unrecognized binary operator");
@@ -12808,6 +12814,38 @@ Array_index_expression::do_get_backend(Translate_context* context)
return ret;
}
+// Export an array index expression.
+
+void
+Array_index_expression::do_export(Export_function_body* efb) const
+{
+ efb->write_c_string("(");
+ this->array_->export_expression(efb);
+ efb->write_c_string(")[");
+
+ Type* old_context = efb->type_context();
+ efb->set_type_context(Type::lookup_integer_type("int"));
+
+ this->start_->export_expression(efb);
+ if (this->end_ == NULL)
+ go_assert(this->cap_ == NULL);
+ else
+ {
+ efb->write_c_string(":");
+ if (!this->end_->is_nil_expression())
+ this->end_->export_expression(efb);
+ if (this->cap_ != NULL)
+ {
+ efb->write_c_string(":");
+ this->cap_->export_expression(efb);
+ }
+ }
+
+ efb->set_type_context(old_context);
+
+ efb->write_c_string("]");
+}
+
// Dump ast representation for an array index expression.
void
@@ -13068,6 +13106,31 @@ String_index_expression::do_get_backend(Translate_context* context)
crash, bstrslice, loc);
}
+// Export a string index expression.
+
+void
+String_index_expression::do_export(Export_function_body* efb) const
+{
+ efb->write_c_string("(");
+ this->string_->export_expression(efb);
+ efb->write_c_string(")[");
+
+ Type* old_context = efb->type_context();
+ efb->set_type_context(Type::lookup_integer_type("int"));
+
+ this->start_->export_expression(efb);
+ if (this->end_ != NULL)
+ {
+ efb->write_c_string(":");
+ if (!this->end_->is_nil_expression())
+ this->end_->export_expression(efb);
+ }
+
+ efb->set_type_context(old_context);
+
+ efb->write_c_string("]");
+}
+
// Dump ast representation for a string index expression.
void
@@ -13338,6 +13401,25 @@ Map_index_expression::get_value_pointer(Gogo* gogo)
return this->value_pointer_;
}
+// Export a map index expression.
+
+void
+Map_index_expression::do_export(Export_function_body* efb) const
+{
+ efb->write_c_string("(");
+ this->map_->export_expression(efb);
+ efb->write_c_string(")[");
+
+ Type* old_context = efb->type_context();
+ efb->set_type_context(this->get_map_type()->key_type());
+
+ this->index_->export_expression(efb);
+
+ efb->set_type_context(old_context);
+
+ efb->write_c_string("]");
+}
+
// Dump ast representation for a map index expression
void
@@ -17974,6 +18056,29 @@ Expression::import_expression(Import_expression* imp, Location loc)
imp->require_c_string(")");
expr = Expression::make_call(expr, args, is_varargs, loc);
}
+ else if (imp->match_c_string("["))
+ {
+ imp->advance(1);
+ Expression* start = Expression::import_expression(imp, loc);
+ Expression* end = NULL;
+ Expression* cap = NULL;
+ if (imp->match_c_string(":"))
+ {
+ imp->advance(1);
+ int c = imp->peek_char();
+ if (c == ':' || c == ']')
+ end = Expression::make_nil(loc);
+ else
+ end = Expression::import_expression(imp, loc);
+ if (imp->match_c_string(":"))
+ {
+ imp->advance(1);
+ cap = Expression::import_expression(imp, loc);
+ }
+ }
+ imp->require_c_string("]");
+ expr = Expression::make_index(expr, start, end, cap, loc);
+ }
else
break;
}