Update scope when adding class members

* src/abg-ir.h (class_decl::add_member_type)
	(class_decl::add_data_member, class_decl::add_member_function):
	Move the inline implementation of these functions ...
	* src:abg-ir.cc (class_decl::add_member_type)
	(class_decl::add_data_member, class_decl::add_member_function):
	... here.  Augment their implementation to properly update the
	scope of the member.
This commit is contained in:
Dodji Seketeli 2013-04-23 11:13:01 +02:00 committed by Dodji Seketeli
parent ed33523dd6
commit a76076c904
2 changed files with 53 additions and 6 deletions

View File

@ -25,6 +25,7 @@
/// @file
#include <assert.h>
#include <vector>
#include <utility>
#include <algorithm>
@ -1103,6 +1104,55 @@ function_decl::~function_decl()
// <function_decl definitions>
// <class_decl definitions>
/// Add a member type to the current instnace of class_decl
///
/// \param the member type to add.
void
class_decl::add_member_type(shared_ptr<member_type>t)
{
decl_base* c = dynamic_pointer_cast<decl_base>(t->as_type())->get_scope();
/// TODO: use our own assertion facility that adds a meaningful
/// error message or something like a structured error.
assert(!c || c == this);
if (!c)
add_decl_to_scope(t, this);
m_member_types.push_back(t);
}
/// Add a data member to the current instance of class_decl.
///
/// \param m the data member to add.
void
class_decl::add_data_member(shared_ptr<data_member> m)
{
decl_base* c = m->get_scope();
/// TODO: use our own assertion facility that adds a meaningful
/// error message or something like a structured error.
assert(!c || c == this);
if (!c)
add_decl_to_scope(m, this);
m_data_members.push_back(m);
}
/// Add a member function to the current instance of class_decl.
///
/// \param m the member function to add.
void
class_decl::add_member_function(shared_ptr<member_function> m)
{
decl_base* c = m->get_scope();
/// TODO: use our own assertion facility that adds a meaningful
/// error message or something like a structured error.
assert(!c || c == this);
if (!c)
add_decl_to_scope(m, this);
m_member_functions.push_back(m);
}
bool
class_decl::operator==(const class_decl& o) const
{

View File

@ -1227,24 +1227,21 @@ public:
{return m_bases;}
void
add_member_type(shared_ptr<member_type>t)
{m_member_types.push_back(t);}
add_member_type(shared_ptr<member_type>t);
const std::list<shared_ptr<member_type> >&
get_member_types() const
{return m_member_types;}
void
add_data_member(shared_ptr<data_member> m)
{m_data_members.push_back(m);}
add_data_member(shared_ptr<data_member> m);
const std::list<shared_ptr<data_member> >&
get_data_members() const
{return m_data_members;}
void
add_member_function(shared_ptr<member_function> m)
{m_member_functions.push_back(m);}
add_member_function(shared_ptr<member_function> m);
const std::list<shared_ptr<member_function> >&
get_member_functions() const