Don't crash when declaring methods on unknown name.

From-SVN: r168131
This commit is contained in:
Ian Lance Taylor 2010-12-21 20:32:36 +00:00
parent 7a8de70f01
commit 059e2a26f5
3 changed files with 20 additions and 2 deletions

View File

@ -3710,6 +3710,18 @@ Named_object::set_function_value(Function* 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.
source_location

View File

@ -1815,6 +1815,10 @@ class Named_object
void
set_function_value(Function*);
// Declare an unknown name as a type declaration.
void
declare_as_type();
// Export this object.
void
export_named_object(Export*) const;

View File

@ -8013,7 +8013,8 @@ Forward_declaration_type::add_method(const std::string& name,
Function* function)
{
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);
}
@ -8026,7 +8027,8 @@ Forward_declaration_type::add_method_declaration(const std::string& name,
source_location location)
{
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();
return td->add_method_declaration(name, type, location);
}