Commit 8a35e18d by Chris Manghane Committed by Ian Lance Taylor

compiler: Use backend interface for unary expressions.

	* go-gcc.cc (Gcc_backend::unary_expression): New function.

From-SVN: r207063
parent 8adcc78b
2014-01-24 Chris Manghane <cmang@google.com>
* go-gcc.cc (Gcc_backend::unary_expression): New function.
2014-01-16 Chris Manghane <cmang@google.com>
* go-gcc.cc (Gcc_backend::conditional_expression): Add btype
......
......@@ -254,6 +254,9 @@ class Gcc_backend : public Backend
Location);
Bexpression*
unary_expression(Operator, Bexpression*, Location);
Bexpression*
binary_expression(Operator, Bexpression*, Bexpression*, Location);
// Statements.
......@@ -1081,6 +1084,47 @@ Gcc_backend::conditional_expression(Btype* btype, Bexpression* condition,
return this->make_expression(ret);
}
// Return an expression for the unary operation OP EXPR.
Bexpression*
Gcc_backend::unary_expression(Operator op, Bexpression* expr, Location location)
{
tree expr_tree = expr->get_tree();
if (expr_tree == error_mark_node
|| TREE_TYPE(expr_tree) == error_mark_node)
return this->error_expression();
tree type_tree = TREE_TYPE(expr_tree);
enum tree_code code;
switch (op)
{
case OPERATOR_MINUS:
{
tree computed_type = excess_precision_type(type_tree);
if (computed_type != NULL_TREE)
{
expr_tree = convert(computed_type, expr_tree);
type_tree = computed_type;
}
code = NEGATE_EXPR;
break;
}
case OPERATOR_NOT:
code = TRUTH_NOT_EXPR;
break;
case OPERATOR_XOR:
code = BIT_NOT_EXPR;
break;
default:
gcc_unreachable();
break;
}
tree ret = fold_build1_loc(location.gcc_location(), code, type_tree,
expr_tree);
return this->make_expression(ret);
}
// Convert a gofrontend operator to an equivalent tree_code.
static enum tree_code
......
......@@ -298,6 +298,12 @@ class Backend
Bexpression* then_expr, Bexpression* else_expr,
Location) = 0;
// Return an expression for the unary operation OP EXPR.
// Supported values of OP are (from operators.h):
// MINUS, NOT, XOR.
virtual Bexpression*
unary_expression(Operator op, Bexpression* expr, Location) = 0;
// Return an expression for the binary operation LEFT OP RIGHT.
// Supported values of OP are (from operators.h):
// EQEQ, NOTEQ, LT, LE, GT, GE, PLUS, MINUS, OR, XOR, MULT, DIV, MOD,
......
......@@ -403,6 +403,11 @@ class Expression
is_constant() const
{ return this->do_is_constant(); }
// Return whether this is an immutable expression.
bool
is_immutable() const
{ return this->do_is_immutable(); }
// If this is not a numeric constant, return false. If it is one,
// return true, and set VAL to hold the value.
bool
......@@ -758,6 +763,11 @@ class Expression
do_is_constant() const
{ return false; }
// Return whether this is an immutable expression.
virtual bool
do_is_immutable() const
{ return false; }
// Return whether this is a constant expression of numeric type, and
// set the Numeric_constant to the value.
virtual bool
......@@ -1196,6 +1206,10 @@ class String_expression : public Expression
{ return true; }
bool
do_is_immutable() const
{ return true; }
bool
do_string_constant_value(std::string* val) const
{
*val = this->val_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment