OSDN Git Service

Make sure variable type is determined when var initialized to var.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 3 Mar 2011 04:28:25 +0000 (04:28 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 3 Mar 2011 04:28:25 +0000 (04:28 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@170643 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/go/gofrontend/expressions.cc
gcc/go/gofrontend/expressions.h
gcc/go/gofrontend/gogo.cc
gcc/go/gofrontend/gogo.h
gcc/go/gofrontend/statements.cc

index 28b7ee6..a94a707 100644 (file)
@@ -957,6 +957,15 @@ Var_expression::do_type()
     gcc_unreachable();
 }
 
     gcc_unreachable();
 }
 
+// Determine the type of a reference to a variable.
+
+void
+Var_expression::do_determine_type(const Type_context*)
+{
+  if (this->variable_->is_variable())
+    this->variable_->var_value()->determine_type();
+}
+
 // Something takes the address of this variable.  This means that we
 // may want to move the variable onto the heap.
 
 // Something takes the address of this variable.  This means that we
 // may want to move the variable onto the heap.
 
index b6fc9c0..2038646 100644 (file)
@@ -915,8 +915,7 @@ class Var_expression : public Expression
   do_type();
 
   void
   do_type();
 
   void
-  do_determine_type(const Type_context*)
-  { }
+  do_determine_type(const Type_context*);
 
   Expression*
   do_copy()
 
   Expression*
   do_copy()
index bb2fcab..5237049 100644 (file)
@@ -1730,7 +1730,7 @@ Shortcuts::convert_shortcut(Block* enclosing, Expression** pshortcut)
   Block* retblock = new Block(enclosing, loc);
   retblock->set_end_location(loc);
 
   Block* retblock = new Block(enclosing, loc);
   retblock->set_end_location(loc);
 
-  Temporary_statement* ts = Statement::make_temporary(Type::make_boolean_type(),
+  Temporary_statement* ts = Statement::make_temporary(Type::lookup_bool_type(),
                                                      left, loc);
   retblock->add_statement(ts);
 
                                                      left, loc);
   retblock->add_statement(ts);
 
@@ -2086,7 +2086,7 @@ Build_recover_thunks::function(Named_object* orig_no)
   ++count;
   std::string can_recover_name = buf;
   new_params->push_back(Typed_identifier(can_recover_name,
   ++count;
   std::string can_recover_name = buf;
   new_params->push_back(Typed_identifier(can_recover_name,
-                                        Type::make_boolean_type(),
+                                        Type::lookup_bool_type(),
                                         orig_fntype->location()));
 
   const Typed_identifier_list* orig_results = orig_fntype->results();
                                         orig_fntype->location()));
 
   const Typed_identifier_list* orig_results = orig_fntype->results();
@@ -2222,7 +2222,7 @@ Build_recover_thunks::function(Named_object* orig_no)
 
   // Add the can_recover argument to the (now) new bindings, and
   // attach it to any recover statements.
 
   // Add the can_recover argument to the (now) new bindings, and
   // attach it to any recover statements.
-  Variable* can_recover_var = new Variable(Type::make_boolean_type(), NULL,
+  Variable* can_recover_var = new Variable(Type::lookup_bool_type(), NULL,
                                           false, true, false, location);
   can_recover_no = new_bindings->add_variable(can_recover_name, NULL,
                                              can_recover_var);
                                           false, true, false, location);
   can_recover_no = new_bindings->add_variable(can_recover_name, NULL,
                                              can_recover_var);
@@ -2273,7 +2273,7 @@ Build_recover_thunks::can_recover_arg(source_location location)
       Typed_identifier_list* param_types = new Typed_identifier_list();
       Type* voidptr_type = Type::make_pointer_type(Type::make_void_type());
       param_types->push_back(Typed_identifier("a", voidptr_type, bloc));
       Typed_identifier_list* param_types = new Typed_identifier_list();
       Type* voidptr_type = Type::make_pointer_type(Type::make_void_type());
       param_types->push_back(Typed_identifier("a", voidptr_type, bloc));
-      Type* boolean_type = Type::make_boolean_type();
+      Type* boolean_type = Type::lookup_bool_type();
       Typed_identifier_list* results = new Typed_identifier_list();
       results->push_back(Typed_identifier("", boolean_type, bloc));
       Function_type* fntype = Type::make_function_type(NULL, param_types,
       Typed_identifier_list* results = new Typed_identifier_list();
       results->push_back(Typed_identifier("", boolean_type, bloc));
       Function_type* fntype = Type::make_function_type(NULL, param_types,
@@ -3216,7 +3216,7 @@ Variable::Variable(Type* type, Expression* init, bool is_global,
     is_address_taken_(false), seen_(false), init_is_lowered_(false),
     type_from_init_tuple_(false), type_from_range_index_(false),
     type_from_range_value_(false), type_from_chan_element_(false),
     is_address_taken_(false), seen_(false), init_is_lowered_(false),
     type_from_init_tuple_(false), type_from_range_index_(false),
     type_from_range_value_(false), type_from_chan_element_(false),
-    is_type_switch_var_(false)
+    is_type_switch_var_(false), determined_type_(false)
 {
   gcc_assert(type != NULL || init != NULL);
   gcc_assert(!is_parameter || init == NULL);
 {
   gcc_assert(type != NULL || init != NULL);
   gcc_assert(!is_parameter || init == NULL);
@@ -3456,6 +3456,10 @@ Variable::type() const
 void
 Variable::determine_type()
 {
 void
 Variable::determine_type()
 {
+  if (this->determined_type_)
+    return;
+  this->determined_type_ = true;
+
   if (this->preinit_ != NULL)
     this->preinit_->determine_types();
 
   if (this->preinit_ != NULL)
     this->preinit_->determine_types();
 
index 8db802e..7a52a51 100644 (file)
@@ -1307,6 +1307,8 @@ class Variable
   bool type_from_chan_element_ : 1;
   // True if this is a variable created for a type switch case.
   bool is_type_switch_var_ : 1;
   bool type_from_chan_element_ : 1;
   // True if this is a variable created for a type switch case.
   bool is_type_switch_var_ : 1;
+  // True if we have determined types.
+  bool determined_type_ : 1;
 };
 
 // A variable which is really the name for a function return value, or
 };
 
 // A variable which is really the name for a function return value, or
index f8f54c4..c443519 100644 (file)
@@ -970,7 +970,7 @@ Tuple_map_assignment_statement::do_lower(Gogo*, Block* enclosing)
   param_types->push_back(Typed_identifier("val", pval_type, bloc));
 
   Typed_identifier_list* ret_types = new Typed_identifier_list();
   param_types->push_back(Typed_identifier("val", pval_type, bloc));
 
   Typed_identifier_list* ret_types = new Typed_identifier_list();
-  ret_types->push_back(Typed_identifier("", Type::make_boolean_type(), bloc));
+  ret_types->push_back(Typed_identifier("", Type::lookup_bool_type(), bloc));
 
   Function_type* fntype = Type::make_function_type(NULL, param_types,
                                                   ret_types, bloc);
 
   Function_type* fntype = Type::make_function_type(NULL, param_types,
                                                   ret_types, bloc);
@@ -2026,7 +2026,7 @@ Thunk_statement::build_struct(Function_type* fntype)
       // we add an argument when building recover thunks.  Handle that
       // here.
       fields->push_back(Struct_field(Typed_identifier("can_recover",
       // we add an argument when building recover thunks.  Handle that
       // here.
       fields->push_back(Struct_field(Typed_identifier("can_recover",
-                                                     Type::make_boolean_type(),
+                                                     Type::lookup_bool_type(),
                                                      location)));
     }
 
                                                      location)));
     }
 
@@ -2103,7 +2103,7 @@ Thunk_statement::build_thunk(Gogo* gogo, const std::string& thunk_name,
       // return value, to disable tail call optimizations which will
       // break the way we check whether recover is permitted.
       thunk_results = new Typed_identifier_list();
       // return value, to disable tail call optimizations which will
       // break the way we check whether recover is permitted.
       thunk_results = new Typed_identifier_list();
-      thunk_results->push_back(Typed_identifier("", Type::make_boolean_type(),
+      thunk_results->push_back(Typed_identifier("", Type::lookup_bool_type(),
                                                location));
     }
 
                                                location));
     }
 
@@ -2135,7 +2135,7 @@ Thunk_statement::build_thunk(Gogo* gogo, const std::string& thunk_name,
 
          Typed_identifier_list* result_types = new Typed_identifier_list();
          result_types->push_back(Typed_identifier("",
 
          Typed_identifier_list* result_types = new Typed_identifier_list();
          result_types->push_back(Typed_identifier("",
-                                                  Type::make_boolean_type(),
+                                                  Type::lookup_bool_type(),
                                                   bloc));
 
          Function_type* t = Type::make_function_type(NULL, param_types,
                                                   bloc));
 
          Function_type* t = Type::make_function_type(NULL, param_types,