diff options
Diffstat (limited to 'gcc/go/go-gcc.cc')
-rw-r--r-- | gcc/go/go-gcc.cc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc index 6a0d1e7..b2760f1 100644 --- a/gcc/go/go-gcc.cc +++ b/gcc/go/go-gcc.cc @@ -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 |