Ensure diff types can only be created by compute_diff

* include/abg-comparison.h (diff::diff): Make constructor
	protected.
	(pointer_diff::pointer_diff): Likewise.
	(pointer_diff::{first_pointer, second_pointer}): Constify the
	return type.
	(compute_diff): Make this a friend of class pointer_diff.
	(reference_diff::reference_diff): Make this constructor protected.
	(compute_diff): Make this a friend of class reference_diff.
	(class_diff::class_diff): Make this constructor protected.
	(compute_diff): Make this a friend of class class_diff.
	(scope_diff::scope_diff): Make this constructor protected.
	(compute_diff): Make this a friend of class scope_diff.
	(function_decl_diff::function_decl_diff): Make this constructor
	protected.
	(type_decl_diff::type_decl_diff): Likewise.
	(typedef_diff::typedef_diff): Likewise.
	(translation_unit_diff::translation_unit_diff): Likewise.
	(compute_diff): Make this a friend of class translation_unit_diff.
	* src/abg-comparison.cc (pointer_diff::{first_pointer,
	second_pointer}): Constify return type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
Dodji Seketeli 2013-11-25 22:46:10 +01:00
parent 7b76446f04
commit 76a6b8b5bc
2 changed files with 51 additions and 26 deletions

View File

@ -86,14 +86,15 @@ class diff
decl_base_sptr first_subject_;
decl_base_sptr second_subject_;
public:
protected:
diff(decl_base_sptr first_subject,
decl_base_sptr second_subject)
: first_subject_(first_subject),
second_subject_(second_subject)
{}
public:
/// Getter of the first subject of the diff.
///
/// @return the first subject of the diff.
@ -138,13 +139,15 @@ class pointer_diff : public diff
struct priv;
shared_ptr<priv> priv_;
public:
protected:
pointer_diff(pointer_type_def_sptr first,
pointer_type_def_sptr second);
pointer_type_def_sptr
public:
const pointer_type_def_sptr
first_pointer() const;
pointer_type_def_sptr
const pointer_type_def_sptr
second_pointer() const;
diff_sptr
@ -158,6 +161,10 @@ public:
virtual void
report(ostream&, const string& indent = "") const;
friend pointer_diff_sptr
compute_diff(pointer_type_def_sptr first,
pointer_type_def_sptr second);
};// end class pointer_diff
pointer_diff_sptr
@ -176,10 +183,11 @@ class reference_diff : public diff
struct priv;
shared_ptr<priv> priv_;
public:
protected:
reference_diff(const reference_type_def_sptr first,
const reference_type_def_sptr second);
public:
reference_type_def_sptr
first_reference() const;
@ -197,6 +205,10 @@ public:
virtual void
report(ostream&, const string& indent = "") const;
friend reference_diff_sptr
compute_diff(reference_type_def_sptr first,
reference_type_def_sptr second);
};// end class reference_diff
reference_diff_sptr
@ -223,11 +235,11 @@ class class_diff : public diff
void
ensure_lookup_tables_populated(void) const;
public:
protected:
class_diff(class_decl_sptr first_subject,
class_decl_sptr second_subject);
public:
//TODO: add change of the name of the type.
shared_ptr<class_decl>
@ -307,13 +319,20 @@ class scope_diff : public diff
void
ensure_lookup_tables_populated();
protected:
scope_diff(scope_decl_sptr first_scope,
scope_decl_sptr second_scope);
public:
friend scope_diff_sptr
compute_diff(const scope_decl_sptr, const scope_decl_sptr, scope_diff_sptr);
compute_diff(const scope_decl_sptr,
const scope_decl_sptr,
scope_diff_sptr);
scope_diff(scope_decl_sptr first_scope,
scope_decl_sptr second_scope);
friend scope_diff_sptr
compute_diff(const scope_decl_sptr first_scope,
const scope_decl_sptr second_scope);
const scope_decl_sptr
first_scope() const;
@ -393,15 +412,15 @@ class function_decl_diff : public diff
const function_decl::parameter_sptr
inserted_parameter_at(int i) const;
public:
protected:
function_decl_diff(const function_decl_sptr first,
const function_decl_sptr second);
public:
friend function_decl_diff_sptr
compute_diff(const function_decl_sptr first,
const function_decl_sptr second);
function_decl_diff(const function_decl_sptr first,
const function_decl_sptr second);
const function_decl_sptr
first_function_decl() const;
@ -441,13 +460,13 @@ class type_decl_diff : public diff
{
type_decl_diff();
public:
protected:
type_decl_diff(const type_decl_sptr, const type_decl_sptr);
public:
friend type_decl_diff_sptr
compute_diff(const type_decl_sptr, const type_decl_sptr);
type_decl_diff(const type_decl_sptr, const type_decl_sptr);
const type_decl_sptr
first_type_decl() const;
@ -477,14 +496,15 @@ class typedef_diff : public diff
typedef_diff();
public:
friend typedef_diff_sptr
compute_diff(const typedef_decl_sptr, const typedef_decl_sptr);
protected:
typedef_diff(const typedef_decl_sptr first,
const typedef_decl_sptr second);
public:
friend typedef_diff_sptr
compute_diff(const typedef_decl_sptr, const typedef_decl_sptr);
const typedef_decl_sptr
first_typedef_decl() const;
@ -515,10 +535,15 @@ typedef shared_ptr<translation_unit_diff> translation_unit_diff_sptr;
class translation_unit_diff : public scope_diff
{
public:
protected:
translation_unit_diff(translation_unit_sptr first,
translation_unit_sptr second);
public:
friend translation_unit_diff_sptr
compute_diff(const translation_unit_sptr first,
const translation_unit_sptr second);
virtual unsigned
length() const;

View File

@ -341,14 +341,14 @@ pointer_diff::pointer_diff(pointer_type_def_sptr first,
/// Getter for the first subject of a pointer diff
///
/// @return the first pointer considered in this pointer diff.
pointer_type_def_sptr
const pointer_type_def_sptr
pointer_diff::first_pointer() const
{return dynamic_pointer_cast<pointer_type_def>(first_subject());}
/// Getter for the second subject of a pointer diff
///
/// @return the second pointer considered in this pointer diff.
pointer_type_def_sptr
const pointer_type_def_sptr
pointer_diff::second_pointer() const
{return dynamic_pointer_cast<pointer_type_def>(second_subject());}