compiler: Simplify making integer expressions.
authorIan Lance Taylor <ian@gcc.gnu.org>
Fri, 24 Oct 2014 01:49:23 +0000 (01:49 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 24 Oct 2014 01:49:23 +0000 (01:49 +0000)
Instead of always needing an mpz_t, add helper functions to
create an integer functions from signed or unsigned long
values.

From-SVN: r216610

gcc/go/gofrontend/expressions.cc
gcc/go/gofrontend/expressions.h
gcc/go/gofrontend/gogo.cc
gcc/go/gofrontend/parse.cc
gcc/go/gofrontend/runtime.cc
gcc/go/gofrontend/statements.cc
gcc/go/gofrontend/types.cc

index a835ee8378fd97b4c8388ff40c4b7a4348b2ea14..0ec65691dd802f0f2f8498007d0243e148a7ab88 100644 (file)
@@ -157,11 +157,8 @@ Expression::convert_for_assignment(Gogo* gogo, Type* lhs_type,
   else if (lhs_type->is_slice_type() && rhs_type->is_nil_type())
     {
       // Assigning nil to a slice.
-      mpz_t zval;
-      mpz_init_set_ui(zval, 0UL);
-      Expression* zero = Expression::make_integer(&zval, NULL, location);
-      mpz_clear(zval);
       Expression* nil = Expression::make_nil(location);
+      Expression* zero = Expression::make_integer_ul(0, NULL, location);
       return Expression::make_slice_value(lhs_type, nil, zero, zero, location);
     }
   else if (rhs_type->is_nil_type())
@@ -491,11 +488,7 @@ Expression::check_bounds(Expression* val, Location loc)
   Expression* index_overflows = Expression::make_boolean(false, loc);
   if (!val_is_unsigned)
     {
-      mpz_t zval;
-      mpz_init_set_ui(zval, 0UL);
-      Expression* zero = Expression::make_integer(&zval, val_type, loc);
-      mpz_clear(zval);
-
+      Expression* zero = Expression::make_integer_ul(0, val_type, loc);
       negative_index = Expression::make_binary(OPERATOR_LT, val, zero, loc);
     }
 
@@ -512,7 +505,7 @@ Expression::check_bounds(Expression* val, Location loc)
       mpz_init(maxval);
       mpz_mul_2exp(maxval, one, bound_type_size - 1);
       mpz_sub_ui(maxval, maxval, 1);
-      Expression* max = Expression::make_integer(&maxval, val_type, loc);
+      Expression* max = Expression::make_integer_z(&maxval, val_type, loc);
       mpz_clear(one);
       mpz_clear(maxval);
 
@@ -1824,8 +1817,8 @@ class Integer_expression : public Expression
       return Expression::make_character(&this->val_, this->type_,
                                        this->location());
     else
-      return Expression::make_integer(&this->val_, this->type_,
-                                     this->location());
+      return Expression::make_integer_z(&this->val_, this->type_,
+                                       this->location());
   }
 
   void
@@ -2047,7 +2040,7 @@ Integer_expression::do_import(Import* imp)
       if (is_character_constant)
        ret = Expression::make_character(&val, NULL, imp->location());
       else
-       ret = Expression::make_integer(&val, NULL, imp->location());
+       ret = Expression::make_integer_z(&val, NULL, imp->location());
       mpz_clear(val);
       return ret;
     }
@@ -2077,14 +2070,38 @@ Integer_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
     ast_dump_context->ostream() << '\'';
 }
 
-// Build a new integer value.
+// Build a new integer value from a multi-precision integer.
 
 Expression*
-Expression::make_integer(const mpz_t* val, Type* type, Location location)
+Expression::make_integer_z(const mpz_t* val, Type* type, Location location)
 {
   return new Integer_expression(val, type, false, location);
 }
 
+// Build a new integer value from an unsigned long.
+
+Expression*
+Expression::make_integer_ul(unsigned long val, Type *type, Location location)
+{
+  mpz_t zval;
+  mpz_init_set_ui(zval, val);
+  Expression* ret = Expression::make_integer_z(&zval, type, location);
+  mpz_clear(zval);
+  return ret;
+}
+
+// Build a new integer value from a signed long.
+
+Expression*
+Expression::make_integer_sl(long val, Type *type, Location location)
+{
+  mpz_t zval;
+  mpz_init_set_si(zval, val);
+  Expression* ret = Expression::make_integer_z(&zval, type, location);
+  mpz_clear(zval);
+  return ret;
+}
+
 // Build a new character constant value.
 
 Expression*
@@ -2593,12 +2610,7 @@ Const_expression::do_lower(Gogo* gogo, Named_object*,
                   "iota is only defined in const declarations");
          iota_value = 0;
        }
-      mpz_t val;
-      mpz_init_set_ui(val, static_cast<unsigned long>(iota_value));
-      Expression* ret = Expression::make_integer(&val, NULL,
-                                                this->location());
-      mpz_clear(val);
-      return ret;
+      return Expression::make_integer_ul(iota_value, NULL, this->location());
     }
 
   // Make sure that the constant itself has been lowered.
@@ -3105,13 +3117,10 @@ Type_conversion_expression::do_lower(Gogo*, Named_object*,
                       p != s.end();
                       p++)
                    {
-                     mpz_t val;
-                     mpz_init_set_ui(val, static_cast<unsigned char>(*p));
-                     Expression* v = Expression::make_integer(&val,
-                                                              element_type,
-                                                              location);
-                     vals->push_back(v);
-                     mpz_clear(val);
+                     unsigned char c = static_cast<unsigned char>(*p);
+                     vals->push_back(Expression::make_integer_ul(c,
+                                                                 element_type,
+                                                                 location));
                    }
                }
              else
@@ -3129,13 +3138,9 @@ Type_conversion_expression::do_lower(Gogo*, Named_object*,
                          adv = 1;
                        }
                      p += adv;
-                     mpz_t val;
-                     mpz_init_set_ui(val, c);
-                     Expression* v = Expression::make_integer(&val,
-                                                              element_type,
-                                                              location);
-                     vals->push_back(v);
-                     mpz_clear(val);
+                     vals->push_back(Expression::make_integer_ul(c,
+                                                                 element_type,
+                                                                 location));
                    }
                }
 
@@ -5419,12 +5424,7 @@ Binary_expression::lower_compare_to_memcmp(Gogo*, Statement_inserter* inserter)
                                               TYPE_INFO_SIZE);
 
   Expression* call = Runtime::make_call(Runtime::MEMCMP, loc, 3, a1, a2, len);
-
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0);
-  Expression* zero = Expression::make_integer(&zval, NULL, loc);
-  mpz_clear(zval);
-
+  Expression* zero = Expression::make_integer_ul(0, NULL, loc);
   return Expression::make_binary(this->op_, call, zero, loc);
 }
 
@@ -5883,10 +5883,9 @@ Binary_expression::do_check_types(Gogo*)
                  if (mpz_sgn(val) < 0)
                    {
                      this->report_error(_("negative shift count"));
-                     mpz_set_ui(val, 0);
                      Location rloc = this->right_->location();
-                     this->right_ = Expression::make_integer(&val, right_type,
-                                                             rloc);
+                     this->right_ = Expression::make_integer_ul(0, right_type,
+                                                                rloc);
                    }
                  mpz_clear(val);
                }
@@ -6343,10 +6342,7 @@ Expression::comparison(Translate_context* context, Type* result_type,
   Type* left_type = left->type();
   Type* right_type = right->type();
 
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0UL);
-  Expression* zexpr = Expression::make_integer(&zval, NULL, location);
-  mpz_clear(zval);
+  Expression* zexpr = Expression::make_integer_ul(0, NULL, location);
 
   if (left_type->is_string_type() && right_type->is_string_type())
     {
@@ -7260,11 +7256,7 @@ Builtin_call_expression::lower_make()
          this->report_error(_("length required when allocating a slice"));
          return Expression::make_error(this->location());
        }
-
-      mpz_t zval;
-      mpz_init_set_ui(zval, 0);
-      len_arg = Expression::make_integer(&zval, NULL, loc);
-      mpz_clear(zval);
+      len_arg = Expression::make_integer_ul(0, NULL, loc);
     }
   else
     {
@@ -8543,7 +8535,7 @@ Builtin_call_expression::do_get_backend(Translate_context* context)
         mpz_t ival;
         nc.get_int(&ival);
         Expression* int_cst =
-            Expression::make_integer(&ival, uintptr_type, location);
+            Expression::make_integer_z(&ival, uintptr_type, location);
         mpz_clear(ival);
         return int_cst->get_backend(context);
       }
@@ -8586,13 +8578,10 @@ Builtin_call_expression::do_get_backend(Translate_context* context)
 
        Type* element_type = at->element_type();
        Btype* element_btype = element_type->get_backend(gogo);
-
-        mpz_t size;
-        size_t element_size = gogo->backend()->type_size(element_btype);
-        mpz_init_set_ui(size, element_size);
-        Expression* size_expr = Expression::make_integer(&size, length->type(), location);
-        mpz_clear(size);
-
+       size_t element_size = gogo->backend()->type_size(element_btype);
+       Expression* size_expr = Expression::make_integer_ul(element_size,
+                                                           length->type(),
+                                                           location);
         Expression* bytecount =
             Expression::make_binary(OPERATOR_MULT, size_expr, length, location);
         Expression* copy = Runtime::make_call(Runtime::COPY, location, 3,
@@ -8615,7 +8604,7 @@ Builtin_call_expression::do_get_backend(Translate_context* context)
         go_assert(arg2->is_variable());
        Expression* arg2_val;
        Expression* arg2_len;
-        mpz_t size;
+       unsigned long size;
        if (arg2->type()->is_string_type()
            && element_type->integer_type() != NULL
            && element_type->integer_type()->is_byte())
@@ -8624,19 +8613,17 @@ Builtin_call_expression::do_get_backend(Translate_context* context)
                                                    location);
            arg2_len = Expression::make_string_info(arg2, STRING_INFO_LENGTH,
                                                    location);
-            mpz_init_set_ui(size, 1UL);
+           size = 1;
          }
        else
          {
            arg2_val = at->get_value_pointer(gogo, arg2);
            arg2_len = at->get_length(gogo, arg2);
            Btype* element_btype = element_type->get_backend(gogo);
-            size_t element_size = gogo->backend()->type_size(element_btype);
-            mpz_init_set_ui(size, element_size);
+           size = gogo->backend()->type_size(element_btype);
          }
         Expression* element_size =
-            Expression::make_integer(&size, NULL, location);
-        mpz_clear(size);
+         Expression::make_integer_ul(size, NULL, location);
 
         Expression* append = Runtime::make_call(Runtime::APPEND, location, 4,
                                                 arg1, arg2_val, arg2_len,
@@ -10762,12 +10749,7 @@ String_index_expression::do_get_backend(Translate_context* context)
 
   Expression* end = NULL;
   if (this->end_->is_nil_expression())
-    {
-      mpz_t neg_one;
-      mpz_init_set_si(neg_one, -1);
-      end = Expression::make_integer(&neg_one, int_type, loc);
-      mpz_clear(neg_one);
-    }
+    end = Expression::make_integer_sl(-1, int_type, loc);
   else
     {
       Expression* bounds_check = Expression::check_bounds(this->end_, loc);
@@ -11076,10 +11058,7 @@ Field_reference_expression::do_lower(Gogo* gogo, Named_object* function,
   // string, it won't garbage collect the bytes.  So we use a
   // [...]byte.
 
-  mpz_t val;
-  mpz_init_set_ui(val, s.length());
-  Expression* length_expr = Expression::make_integer(&val, NULL, loc);
-  mpz_clear(val);
+  Expression* length_expr = Expression::make_integer_ul(s.length(), NULL, loc);
 
   Type* byte_type = gogo->lookup_global("byte")->type_value();
   Type* array_type = Type::make_array_type(byte_type, length_expr);
@@ -11087,10 +11066,8 @@ Field_reference_expression::do_lower(Gogo* gogo, Named_object* function,
   Expression_list* bytes = new Expression_list();
   for (std::string::const_iterator p = s.begin(); p != s.end(); p++)
     {
-      mpz_init_set_ui(val, *p);
-      Expression* byte = Expression::make_integer(&val, NULL, loc);
-      mpz_clear(val);
-      bytes->push_back(byte);
+      unsigned char c = static_cast<unsigned char>(*p);
+      bytes->push_back(Expression::make_integer_ul(c, NULL, loc));
     }
 
   Expression* e = Expression::make_composite_literal(array_type, 0, false,
@@ -12490,20 +12467,19 @@ class Slice_construction_expression : public Array_construction_expression
   {
     go_assert(type->is_slice_type());
 
-    mpz_t lenval;
+    unsigned long lenval;
     Expression* length;
     if (vals == NULL || vals->empty())
-      mpz_init_set_ui(lenval, 0);
+      lenval = 0;
     else
       {
        if (this->indexes() == NULL)
-         mpz_init_set_ui(lenval, vals->size());
+         lenval = vals->size();
        else
-         mpz_init_set_ui(lenval, indexes->back() + 1);
+         lenval = indexes->back() + 1;
       }
     Type* int_type = Type::lookup_integer_type("int");
-    length = Expression::make_integer(&lenval, int_type, location);
-    mpz_clear(lenval);
+    length = Expression::make_integer_ul(lenval, int_type, location);
     Type* element_type = type->array_type()->element_type();
     this->valtype_ = Type::make_array_type(element_type, length);
   }
@@ -12722,11 +12698,7 @@ Map_construction_expression::do_flatten(Gogo* gogo, Named_object*,
                                                         key_value_pair, loc));
         }
 
-      mpz_t lenval;
-      mpz_init_set_ui(lenval, i);
-      Expression* element_count = Expression::make_integer(&lenval, NULL, loc);
-      mpz_clear(lenval);
-
+      Expression* element_count = Expression::make_integer_ul(i, NULL, loc);
       Type* ctor_type =
           Type::make_array_type(this->element_type_, element_count);
       Expression* constructor =
@@ -12831,10 +12803,7 @@ Map_construction_expression::do_get_backend(Translate_context* context)
   Expression* descriptor = Expression::make_map_descriptor(mt, loc);
 
   Type* uintptr_t = Type::lookup_integer_type("uintptr");
-  mpz_t countval;
-  mpz_init_set_ui(countval, i);
-  Expression* count = Expression::make_integer(&countval, uintptr_t, loc);
-  mpz_clear(countval);
+  Expression* count = Expression::make_integer_ul(i, uintptr_t, loc);
 
   Expression* entry_size =
       Expression::make_type_info(this->element_type_, TYPE_INFO_SIZE);
@@ -13463,10 +13432,7 @@ Composite_literal_expression::make_array(
            }
        }
 
-      mpz_t vlen;
-      mpz_init_set_ui(vlen, size);
-      Expression* elen = Expression::make_integer(&vlen, NULL, location);
-      mpz_clear(vlen);
+      Expression* elen = Expression::make_integer_ul(size, NULL, location);
       at = Type::make_array_type(at->element_type(), elen);
       type = at;
     }
@@ -14903,12 +14869,10 @@ Struct_field_offset_expression::do_get_backend(Translate_context* context)
   Btype* btype = this->type_->get_backend(gogo);
 
   size_t offset = gogo->backend()->type_field_offset(btype, i);
-  mpz_t offsetval;
-  mpz_init_set_ui(offsetval, offset);
   Type* uptr_type = Type::lookup_integer_type("uintptr");
-  Expression* ret = Expression::make_integer(&offsetval, uptr_type,
-                                            Linemap::predeclared_location());
-  mpz_clear(offsetval);
+  Expression* ret =
+    Expression::make_integer_ul(offset, uptr_type,
+                               Linemap::predeclared_location());
   return ret->get_backend(context);
 }
 
@@ -15980,7 +15944,7 @@ Numeric_constant::expression(Location loc) const
   switch (this->classification_)
     {
     case NC_INT:
-      return Expression::make_integer(&this->u_.int_val, this->type_, loc);
+      return Expression::make_integer_z(&this->u_.int_val, this->type_, loc);
     case NC_RUNE:
       return Expression::make_character(&this->u_.int_val, this->type_, loc);
     case NC_FLOAT:
index c6b163e715d0829bd4810697e0282e394e389c91..7bf38d7f49fee192121dd77b65e716be40f6cfd7 100644 (file)
@@ -214,10 +214,20 @@ class Expression
   static Expression*
   make_character(const mpz_t*, Type*, Location);
 
-  // Make a constant integer expression.  TYPE should be NULL for an
-  // abstract type.
+  // Make a constant integer expression from a multi-precision
+  // integer.  TYPE should be NULL for an abstract type.
+  static Expression*
+  make_integer_z(const mpz_t*, Type*, Location);
+
+  // Make a constant integer expression from an unsigned long.  TYPE
+  // should be NULL for an abstract type.
+  static Expression*
+  make_integer_ul(unsigned long, Type*, Location);
+
+  // Make a constant integer expression from a signed long.  TYPE
+  // should be NULL for an abstract type.
   static Expression*
-  make_integer(const mpz_t*, Type*, Location);
+  make_integer_sl(long, Type*, Location);
 
   // Make a constant float expression.  TYPE should be NULL for an
   // abstract type.
index 7c3ebce103c7128ebf0d07b533d1cd568bcc2faa..d6ba272dbd4adfd4669e161ad008d561f44a8e54 100644 (file)
@@ -587,11 +587,7 @@ Gogo::zero_value(Type *type)
       // We will change the type later, when we know the size.
       Type* byte_type = this->lookup_global("byte")->type_value();
 
-      mpz_t val;
-      mpz_init_set_ui(val, 0);
-      Expression* zero = Expression::make_integer(&val, NULL, bloc);
-      mpz_clear(val);
-
+      Expression* zero = Expression::make_integer_ul(0, NULL, bloc);
       Type* array_type = Type::make_array_type(byte_type, zero);
 
       Variable* var = new Variable(array_type, NULL, true, false, false, bloc);
@@ -738,11 +734,8 @@ Gogo::register_gc_vars(const std::vector<Named_object*>& var_gc,
                                                           "__size", uint_type);
 
   Location builtin_loc = Linemap::predeclared_location();
-  size_t count = var_gc.size();
-  mpz_t lenval;
-  mpz_init_set_ui(lenval, count);
-  Expression* length = Expression::make_integer(&lenval, NULL, builtin_loc);
-  mpz_clear(lenval);
+  Expression* length = Expression::make_integer_ul(var_gc.size(), NULL,
+                                                  builtin_loc);
 
   Array_type* root_array_type = Type::make_array_type(root_type, length);
   Type* ptdt = Type::make_type_descriptor_ptr_type();
@@ -783,10 +776,7 @@ Gogo::register_gc_vars(const std::vector<Named_object*>& var_gc,
   Expression* nil = Expression::make_nil(builtin_loc);
   null_init->push_back(nil);
 
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0UL);
-  Expression* zero = Expression::make_integer(&zval, NULL, builtin_loc);
-  mpz_clear(zval);
+  Expression *zero = Expression::make_integer_ul(0, NULL, builtin_loc);
   null_init->push_back(zero);
 
   Expression* null_root_ctor =
@@ -4029,10 +4019,7 @@ Build_recover_thunks::can_recover_arg(Location location)
   Expression* fn = Expression::make_func_reference(builtin_return_address,
                                                   NULL, location);
 
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0UL);
-  Expression* zexpr = Expression::make_integer(&zval, NULL, location);
-  mpz_clear(zval);
+  Expression* zexpr = Expression::make_integer_ul(0, NULL, location);
   Expression_list *args = new Expression_list();
   args->push_back(zexpr);
 
@@ -4067,10 +4054,8 @@ Expression*
 Gogo::runtime_error(int code, Location location)
 {
   Type* int32_type = Type::lookup_integer_type("int32");
-  mpz_t val;
-  mpz_init_set_ui(val, code);
-  Expression* code_expr = Expression::make_integer(&val, int32_type, location);
-  mpz_clear(val);
+  Expression* code_expr = Expression::make_integer_ul(code, int32_type,
+                                                     location);
   return Runtime::make_call(Runtime::RUNTIME_ERROR, location, 1, code_expr);
 }
 
index c4bcf058d8eacd315eee97194fd1ee34054ee50e..dfb3380c90b037c8516c3ac6eed7a86cf22f6abb 100644 (file)
@@ -2510,8 +2510,8 @@ Parse::operand(bool may_be_sink, bool* is_parenthesized)
       return ret;
 
     case Token::TOKEN_INTEGER:
-      ret = Expression::make_integer(token->integer_value(), NULL,
-                                    token->location());
+      ret = Expression::make_integer_z(token->integer_value(), NULL,
+                                      token->location());
       this->advance_token();
       return ret;
 
@@ -3129,12 +3129,7 @@ Parse::index(Expression* expr)
   if (!this->peek_token()->is_op(OPERATOR_COLON))
     start = this->expression(PRECEDENCE_NORMAL, false, true, NULL, NULL);
   else
-    {
-      mpz_t zero;
-      mpz_init_set_ui(zero, 0);
-      start = Expression::make_integer(&zero, NULL, location);
-      mpz_clear(zero);
-    }
+    start = Expression::make_integer_ul(0, NULL, location);
 
   Expression* end = NULL;
   if (this->peek_token()->is_op(OPERATOR_COLON))
index 4370a580fca2ad768769e7724cb30fb5a3247fc0..de68f64b59357f2e38f3900f6a94505082c7e9a7 100644 (file)
@@ -397,12 +397,8 @@ Type*
 Runtime::map_iteration_type()
 {
   const unsigned long map_iteration_size = 4;
-
-  mpz_t ival;
-  mpz_init_set_ui(ival, map_iteration_size);
-  Expression* iexpr = Expression::make_integer(&ival, NULL,
-                                               Linemap::predeclared_location());
-  mpz_clear(ival);
-
+  Expression* iexpr =
+    Expression::make_integer_ul(map_iteration_size, NULL,
+                               Linemap::predeclared_location());
   return Type::make_array_type(runtime_function_type(RFT_POINTER), iexpr);
 }
index 183aaf4f8ab516f5c05594751cc0d23cffc59517..57d7f9da91c381e6608e745122240ad43a5c9112 100644 (file)
@@ -1838,12 +1838,7 @@ Statement*
 Inc_dec_statement::do_lower(Gogo*, Named_object*, Block*, Statement_inserter*)
 {
   Location loc = this->location();
-
-  mpz_t oval;
-  mpz_init_set_ui(oval, 1UL);
-  Expression* oexpr = Expression::make_integer(&oval, this->expr_->type(), loc);
-  mpz_clear(oval);
-
+  Expression* oexpr = Expression::make_integer_ul(1, this->expr_->type(), loc);
   Operator op = this->is_inc_ ? OPERATOR_PLUSEQ : OPERATOR_MINUSEQ;
   return Statement::make_assignment_operation(op, this->expr_, oexpr, loc);
 }
@@ -3441,7 +3436,7 @@ Case_clauses::Case_clause::get_backend(Translate_context* context,
                  continue;
                }
              go_assert(nc.type() != NULL);
-             e = Expression::make_integer(&ival, nc.type(), e->location());
+             e = Expression::make_integer_z(&ival, nc.type(), e->location());
              mpz_clear(ival);
            }
 
@@ -4559,10 +4554,8 @@ Select_clauses::Select_clause::lower(Gogo* gogo, Named_object* function,
 
   Expression* selref = Expression::make_temporary_reference(sel, loc);
 
-  mpz_t ival;
-  mpz_init_set_ui(ival, this->index_);
-  Expression* index_expr = Expression::make_integer(&ival, NULL, loc);
-  mpz_clear(ival);
+  Expression* index_expr = Expression::make_integer_ul(this->index_, NULL,
+                                                      loc);
 
   if (this->is_default_)
     {
@@ -4907,11 +4900,8 @@ Select_clauses::get_backend(Translate_context* context,
        ++p, ++i)
     {
       int index = p->index();
-      mpz_t ival;
-      mpz_init_set_ui(ival, index);
-      Expression* index_expr = Expression::make_integer(&ival, int32_type,
-                                                       location);
-      mpz_clear(ival);
+      Expression* index_expr = Expression::make_integer_ul(index, int32_type,
+                                                          location);
       cases[i].push_back(index_expr->get_backend(context));
 
       Bstatement* s = p->get_statements_backend(context);
@@ -4993,11 +4983,8 @@ Select_statement::do_lower(Gogo* gogo, Named_object* function,
 
   go_assert(this->sel_ == NULL);
 
-  mpz_t ival;
-  mpz_init_set_ui(ival, this->clauses_->size());
-  Expression* size_expr = Expression::make_integer(&ival, NULL, loc);
-  mpz_clear(ival);
-
+  Expression* size_expr = Expression::make_integer_ul(this->clauses_->size(),
+                                                     NULL, loc);
   Expression* call = Runtime::make_call(Runtime::NEWSELECT, loc, 1, size_expr);
 
   this->sel_ = Statement::make_temporary(NULL, call, loc);
@@ -5488,10 +5475,7 @@ For_range_statement::lower_range_array(Gogo* gogo,
                                                            len_call, loc);
   init->add_statement(len_temp);
 
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0UL);
-  Expression* zexpr = Expression::make_integer(&zval, NULL, loc);
-  mpz_clear(zval);
+  Expression* zexpr = Expression::make_integer_ul(0, NULL, loc);
 
   Temporary_reference_expression* tref =
     Expression::make_temporary_reference(index_temp, loc);
@@ -5589,10 +5573,7 @@ For_range_statement::lower_range_slice(Gogo* gogo,
                                                            len_call, loc);
   init->add_statement(len_temp);
 
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0UL);
-  Expression* zexpr = Expression::make_integer(&zval, NULL, loc);
-  mpz_clear(zval);
+  Expression* zexpr = Expression::make_integer_ul(0, NULL, loc);
 
   Temporary_reference_expression* tref =
     Expression::make_temporary_reference(index_temp, loc);
@@ -5681,9 +5662,7 @@ For_range_statement::lower_range_string(Gogo*,
     Statement::make_temporary(index_temp->type(), NULL, loc);
   init->add_statement(next_index_temp);
 
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0UL);
-  Expression* zexpr = Expression::make_integer(&zval, NULL, loc);
+  Expression* zexpr = Expression::make_integer_ul(0, NULL, loc);
 
   Temporary_reference_expression* ref =
     Expression::make_temporary_reference(index_temp, loc);
@@ -5742,8 +5721,7 @@ For_range_statement::lower_range_string(Gogo*,
   iter_init->add_statement(s);
 
   ref = Expression::make_temporary_reference(next_index_temp, loc);
-  zexpr = Expression::make_integer(&zval, NULL, loc);
-  mpz_clear(zval);
+  zexpr = Expression::make_integer_ul(0, NULL, loc);
   Expression* equals = Expression::make_binary(OPERATOR_EQEQ, ref, zexpr, loc);
 
   Block* then_block = new Block(iter_init, loc);
@@ -5823,18 +5801,11 @@ For_range_statement::lower_range_map(Gogo*,
   //   hiter[0] != nil
 
   ref = Expression::make_temporary_reference(hiter, loc);
-
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0UL);
-  Expression* zexpr = Expression::make_integer(&zval, NULL, loc);
-  mpz_clear(zval);
-
+  Expression* zexpr = Expression::make_integer_ul(0, NULL, loc);
   Expression* index = Expression::make_index(ref, zexpr, NULL, NULL, loc);
-
   Expression* ne = Expression::make_binary(OPERATOR_NOTEQ, index,
                                           Expression::make_nil(loc),
                                           loc);
-
   *pcond = ne;
 
   // Set *PITER_INIT to
index 0d66abf50813e9311fc9e72438fccc872432bcec..ba07461391969980a05dc5b3652de712a749f8b5 100644 (file)
@@ -1956,9 +1956,8 @@ Type::type_descriptor_constructor(Gogo* gogo, int runtime_type_kind,
     runtime_type_kind |= RUNTIME_TYPE_KIND_NO_POINTERS;
   Struct_field_list::const_iterator p = fields->begin();
   go_assert(p->is_field_name("kind"));
-  mpz_t iv;
-  mpz_init_set_ui(iv, runtime_type_kind);
-  vals->push_back(Expression::make_integer(&iv, p->type(), bloc));
+  vals->push_back(Expression::make_integer_ul(runtime_type_kind, p->type(),
+                                             bloc));
 
   ++p;
   go_assert(p->is_field_name("align"));
@@ -1982,8 +1981,7 @@ Type::type_descriptor_constructor(Gogo* gogo, int runtime_type_kind,
     h = name->hash_for_method(gogo);
   else
     h = this->hash_for_method(gogo);
-  mpz_set_ui(iv, h);
-  vals->push_back(Expression::make_integer(&iv, p->type(), bloc));
+  vals->push_back(Expression::make_integer_ul(h, p->type(), bloc));
 
   ++p;
   go_assert(p->is_field_name("hashfn"));
@@ -2048,8 +2046,6 @@ Type::type_descriptor_constructor(Gogo* gogo, int runtime_type_kind,
   ++p;
   go_assert(p == fields->end());
 
-  mpz_clear(iv);
-
   return Expression::make_struct_composite_literal(td_type, vals, bloc);
 }
 
@@ -2172,23 +2168,14 @@ Type::gc_symbol_constructor(Gogo* gogo)
   vals->push_back(Expression::make_type_info(this,
                                             Expression::TYPE_INFO_SIZE));
 
-  mpz_t off;
-  mpz_init_set_ui(off, 0UL);
-  Expression* offset = Expression::make_integer(&off, uintptr_t, bloc);
-  mpz_clear(off);
+  Expression* offset = Expression::make_integer_ul(0, uintptr_t, bloc);
 
   this->do_gc_symbol(gogo, &vals, &offset, 0);
 
-  mpz_t end;
-  mpz_init_set_ui(end, GC_END);
-  vals->push_back(Expression::make_integer(&end, uintptr_t, bloc));
-  mpz_clear(end);
-
-  mpz_t lenval;
-  mpz_init_set_ui(lenval, vals->size() + 1);
-  Expression* len = Expression::make_integer(&lenval, NULL, bloc);
-  mpz_clear(lenval);
+  vals->push_back(Expression::make_integer_ul(GC_END, uintptr_t, bloc));
 
+  Expression* len = Expression::make_integer_ul(vals->size() + 1, NULL,
+                                               bloc);
   Array_type* gc_symbol_type = Type::make_array_type(uintptr_t, len);
   return Expression::make_array_composite_literal(gc_symbol_type, vals, bloc);
 }
@@ -3267,10 +3254,8 @@ String_type::do_gc_symbol(Gogo*, Expression_list** vals,
 {
   Location bloc = Linemap::predeclared_location();
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
-  mpz_t opval;
-  mpz_init_set_ui(opval, GC_STRING);
-  (*vals)->push_back(Expression::make_integer(&opval, uintptr_type, bloc));
-  mpz_clear(opval);
+  (*vals)->push_back(Expression::make_integer_ul(GC_STRING, uintptr_type,
+                                                bloc));
   (*vals)->push_back(*offset);
   this->advance_gc_offset(offset);
 }
@@ -3942,10 +3927,7 @@ Function_type::do_gc_symbol(Gogo*, Expression_list** vals,
 
   // We use GC_APTR here because we do not currently have a way to describe the
   // the type of the possible function closure.  FIXME.
-  mpz_t opval;
-  mpz_init_set_ui(opval, GC_APTR);
-  (*vals)->push_back(Expression::make_integer(&opval, uintptr_type, bloc));
-  mpz_clear(opval);
+  (*vals)->push_back(Expression::make_integer_ul(GC_APTR, uintptr_type, bloc));
   (*vals)->push_back(*offset);
   this->advance_gc_offset(offset);
 }
@@ -4361,10 +4343,8 @@ Pointer_type::do_gc_symbol(Gogo*, Expression_list** vals,
   Location loc = Linemap::predeclared_location();
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
 
-  mpz_t opval;
-  mpz_init_set_ui(opval, this->to_type_->has_pointer() ? GC_PTR : GC_APTR);
-  (*vals)->push_back(Expression::make_integer(&opval, uintptr_type, loc));
-  mpz_clear(opval);
+  unsigned long opval = this->to_type_->has_pointer() ? GC_PTR : GC_APTR;
+  (*vals)->push_back(Expression::make_integer_ul(opval, uintptr_type, loc));
   (*vals)->push_back(*offset);
 
   if (this->to_type_->has_pointer())
@@ -5297,10 +5277,7 @@ Struct_type::write_hash_function(Gogo* gogo, Named_type*,
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
 
   // Get a 0.
-  mpz_t ival;
-  mpz_init_set_ui(ival, 0);
-  Expression* zero = Expression::make_integer(&ival, uintptr_type, bloc);
-  mpz_clear(ival);
+  Expression* zero = Expression::make_integer_ul(0, uintptr_type, bloc);
 
   // Make a temporary to hold the return value, initialized to 0.
   Temporary_statement* retval = Statement::make_temporary(uintptr_type, zero,
@@ -5329,11 +5306,8 @@ Struct_type::write_hash_function(Gogo* gogo, Named_type*,
       else
        {
          // Multiply retval by 33.
-         mpz_init_set_ui(ival, 33);
-         Expression* i33 = Expression::make_integer(&ival, uintptr_type,
-                                                    bloc);
-         mpz_clear(ival);
-
+         Expression* i33 = Expression::make_integer_ul(33, uintptr_type,
+                                                       bloc);
          ref = Expression::make_temporary_reference(retval, bloc);
          Statement* s = Statement::make_assignment_operation(OPERATOR_MULTEQ,
                                                              ref, i33, bloc);
@@ -5872,10 +5846,7 @@ Array_type::write_hash_function(Gogo* gogo, Named_type* name,
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
 
   // Get a 0.
-  mpz_t ival;
-  mpz_init_set_ui(ival, 0);
-  Expression* zero = Expression::make_integer(&ival, uintptr_type, bloc);
-  mpz_clear(ival);
+  Expression* zero = Expression::make_integer_ul(0, uintptr_type, bloc);
 
   // Make a temporary to hold the return value, initialized to 0.
   Temporary_statement* retval = Statement::make_temporary(uintptr_type, zero,
@@ -5909,9 +5880,7 @@ Array_type::write_hash_function(Gogo* gogo, Named_type* name,
   gogo->start_block(bloc);
 
   // Multiply retval by 33.
-  mpz_init_set_ui(ival, 33);
-  Expression* i33 = Expression::make_integer(&ival, uintptr_type, bloc);
-  mpz_clear(ival);
+  Expression* i33 = Expression::make_integer_ul(33, uintptr_type, bloc);
 
   ref = Expression::make_temporary_reference(retval, bloc);
   Statement* s = Statement::make_assignment_operation(OPERATOR_MULTEQ, ref,
@@ -6431,10 +6400,8 @@ Array_type::slice_gc_symbol(Gogo* gogo, Expression_list** vals,
   size_t element_size = gogo->backend()->type_size(ebtype);
 
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
-  mpz_t opval;
-  mpz_init_set_ui(opval, element_size == 0 ? GC_APTR : GC_SLICE);
-  (*vals)->push_back(Expression::make_integer(&opval, uintptr_type, bloc));
-  mpz_clear(opval);
+  unsigned long opval = element_size == 0 ? GC_APTR : GC_SLICE;
+  (*vals)->push_back(Expression::make_integer_ul(opval, uintptr_type, bloc));
   (*vals)->push_back(*offset);
 
   if (element_size != 0)
@@ -6472,12 +6439,10 @@ Array_type::array_gc_symbol(Gogo* gogo, Expression_list** vals,
     {
       Type* uintptr_type = Type::lookup_integer_type("uintptr");
 
-      mpz_t op;
       if (stack_size < GC_STACK_CAPACITY)
        {
-         mpz_init_set_ui(op, GC_ARRAY_START);
-         (*vals)->push_back(Expression::make_integer(&op, uintptr_type, bloc));
-         mpz_clear(op);
+         (*vals)->push_back(Expression::make_integer_ul(GC_ARRAY_START,
+                                                        uintptr_type, bloc));
          (*vals)->push_back(*offset);
          Expression* uintptr_len =
            Expression::make_cast(uintptr_type, this->length_, bloc);
@@ -6488,20 +6453,17 @@ Array_type::array_gc_symbol(Gogo* gogo, Expression_list** vals,
                                       Expression::TYPE_INFO_SIZE);
          (*vals)->push_back(width);
 
-         mpz_t zero;
-         mpz_init_set_ui(zero, 0UL);
-         Expression* offset2 =
-           Expression::make_integer(&zero, uintptr_type, bloc);
-         mpz_clear(zero);
+         Expression* offset2 = Expression::make_integer_ul(0, uintptr_type,
+                                                           bloc);
 
          Type::gc_symbol(gogo, element_type, vals, &offset2, stack_size + 1);
-         mpz_init_set_ui(op, GC_ARRAY_NEXT);
-         (*vals)->push_back(Expression::make_integer(&op, uintptr_type, bloc));
+         (*vals)->push_back(Expression::make_integer_ul(GC_ARRAY_NEXT,
+                                                        uintptr_type, bloc));
        }
       else
        {
-         mpz_init_set_ui(op, GC_REGION);
-         (*vals)->push_back(Expression::make_integer(&op, uintptr_type, bloc));
+         (*vals)->push_back(Expression::make_integer_ul(GC_REGION,
+                                                        uintptr_type, bloc));
          (*vals)->push_back(*offset);
 
          Expression* width =
@@ -6509,7 +6471,6 @@ Array_type::array_gc_symbol(Gogo* gogo, Expression_list** vals,
          (*vals)->push_back(width);
          (*vals)->push_back(Expression::make_gc_symbol(this));
        }
-      mpz_clear(op);
       this->advance_gc_offset(offset);
     }
 }
@@ -6833,10 +6794,7 @@ Map_type::do_gc_symbol(Gogo*, Expression_list** vals,
   Location bloc = Linemap::predeclared_location();
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
 
-  mpz_t opval;
-  mpz_init_set_ui(opval, GC_APTR);
-  (*vals)->push_back(Expression::make_integer(&opval, uintptr_type, bloc));
-  mpz_clear(opval);
+  (*vals)->push_back(Expression::make_integer_ul(GC_APTR, uintptr_type, bloc));
   (*vals)->push_back(*offset);
   this->advance_gc_offset(offset);
 }
@@ -6989,10 +6947,7 @@ Channel_type::do_type_descriptor(Gogo* gogo, Named_type* name)
     val |= 1;
   if (this->may_send_)
     val |= 2;
-  mpz_t iv;
-  mpz_init_set_ui(iv, val);
-  vals->push_back(Expression::make_integer(&iv, p->type(), bloc));
-  mpz_clear(iv);
+  vals->push_back(Expression::make_integer_ul(val, p->type(), bloc));
 
   ++p;
   go_assert(p == fields->end());
@@ -7023,10 +6978,8 @@ Channel_type::do_gc_symbol(Gogo*, Expression_list** vals,
   Location bloc = Linemap::predeclared_location();
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
 
-  mpz_t opval;
-  mpz_init_set_ui(opval, GC_CHAN_PTR);
-  (*vals)->push_back(Expression::make_integer(&opval, uintptr_type, bloc));
-  mpz_clear(opval);
+  (*vals)->push_back(Expression::make_integer_ul(GC_CHAN_PTR, uintptr_type,
+                                                bloc));
   (*vals)->push_back(*offset);
  
   Type* unsafeptr_type = Type::make_pointer_type(Type::make_void_type());
@@ -7935,11 +7888,8 @@ Interface_type::do_gc_symbol(Gogo*, Expression_list** vals,
   Location bloc = Linemap::predeclared_location();
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
 
-  mpz_t opval;
-  mpz_init_set_ui(opval, this->is_empty() ? GC_EFACE : GC_IFACE);
-  (*vals)->push_back(Expression::make_integer(&opval, uintptr_type,
-                                             bloc));
-  mpz_clear(opval);
+  unsigned long opval = this->is_empty() ? GC_EFACE : GC_IFACE;
+  (*vals)->push_back(Expression::make_integer_ul(opval, uintptr_type, bloc));
   (*vals)->push_back(*offset);
   this->advance_gc_offset(offset);
 }