Commit 059e2a26 by Ian Lance Taylor

Don't crash when declaring methods on unknown name.

From-SVN: r168131
parent 7a8de70f
...@@ -3710,6 +3710,18 @@ Named_object::set_function_value(Function* function) ...@@ -3710,6 +3710,18 @@ Named_object::set_function_value(Function* function)
this->u_.func_value = function; this->u_.func_value = function;
} }
// Declare an unknown object as a type declaration.
void
Named_object::declare_as_type()
{
gcc_assert(this->classification_ == NAMED_OBJECT_UNKNOWN);
Unknown_name* unk = this->u_.unknown_value;
this->classification_ = NAMED_OBJECT_TYPE_DECLARATION;
this->u_.type_declaration = new Type_declaration(unk->location());
delete unk;
}
// Return the location of a named object. // Return the location of a named object.
source_location source_location
......
...@@ -1815,6 +1815,10 @@ class Named_object ...@@ -1815,6 +1815,10 @@ class Named_object
void void
set_function_value(Function*); set_function_value(Function*);
// Declare an unknown name as a type declaration.
void
declare_as_type();
// Export this object. // Export this object.
void void
export_named_object(Export*) const; export_named_object(Export*) const;
......
...@@ -8013,7 +8013,8 @@ Forward_declaration_type::add_method(const std::string& name, ...@@ -8013,7 +8013,8 @@ Forward_declaration_type::add_method(const std::string& name,
Function* function) Function* function)
{ {
Named_object* no = this->named_object(); Named_object* no = this->named_object();
gcc_assert(no->is_type_declaration()); if (no->is_unknown())
no->declare_as_type();
return no->type_declaration_value()->add_method(name, function); return no->type_declaration_value()->add_method(name, function);
} }
...@@ -8026,7 +8027,8 @@ Forward_declaration_type::add_method_declaration(const std::string& name, ...@@ -8026,7 +8027,8 @@ Forward_declaration_type::add_method_declaration(const std::string& name,
source_location location) source_location location)
{ {
Named_object* no = this->named_object(); Named_object* no = this->named_object();
gcc_assert(no->is_type_declaration()); if (no->is_unknown())
no->declare_as_type();
Type_declaration* td = no->type_declaration_value(); Type_declaration* td = no->type_declaration_value();
return td->add_method_declaration(name, type, location); return td->add_method_declaration(name, type, location);
} }
......
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