libabigail/include/abg-comp-filter.h
Giuliano Procida dbef379a96 Support incomplete enums in core and diff code.
This is an initial implementation of the support for incomplete, also
known as forward-declared, enum types. I've not made any attempt to
refactor or share logic with the struct/union code.

	* include/abg-comp-filter.h (has_decl_only_def_change) : Declare
	New function.
	* src/abg-comp-filter.cc (there_is_a_decl_only_enum): Define new
	static function and ...
	(type_size_changed): ... use it here.
	(has_decl_only_def_change): Define new function and ...
	(categorize_harm{less, ful}_diff_node): ... use it here.
	* include/abg-fwd.h (enums_type, decl_base_wptr): Declare new
	typedefs.
	(look_through_decl_only_class): Declare new overload for
	class_or_union*.
	(is_compatible_with_enum_type, is_compatible_with_enum_type)
	(look_through_decl_only, lookup_enum_types, lookup_enum_types):
	Declare new functions.
	* include/abg-ir.h (decl_base::{get_is_declaration_only,
	set_is_declaration_only, set_definition_of_declaration,
	get_definition_of_declaration,
	get_naked_definition_of_declaration}): Declare new member
	functions.  They were moved here from the class_or_union class.
	(class_or_union::{get_earlier_declaration,
	set_earlier_declaration, get_definition_of_declaration,
	set_definition_of_declaration,
	get_naked_definition_of_declaration, get_is_declaration_only,
	set_is_declaration_only}): Remove these member functions.
	* src/abg-ir.cc (decl_base::priv::{declaration_,
	definition_of_declaration_, naked_definition_of_declaration_,
	is_declaration_only_}): Define data members.  Moved here from
	class_or_union.
	(decl_base::priv::priv): Adjust to initialize the new data
	members.
	(decl_base::{get_earlier_declaration, set_earlier_declaration,
	get_definition_of_declaration,
	get_naked_definition_of_declaration, get_is_declaration_only,
	set_is_declaration_only, set_definition_of_declaration}): Define
	member functions.
	(operator|): In the overload for (change_kind, change_kind),
	adjust the return type of the call to
	decl_base::get_definition_of_declaration.
	(look_through_decl_only): Define new function.
	(look_through_decl_only_class): Adjust.
	(look_through_decl_only_enum): Likewise.
	(maybe_update_types_lookup_map<class_decl>): Adjust return type of
	call to decl_base::get_definition_of_declaration.
	(types_defined_same_linux_kernel_corpus_public): Use
	look_through_decl_only_class rather than open coding it.
	(class_or_union::priv::{declaration_, definition_of_declaration_,
	naked_definition_of_declaration_, is_declaration_only_}): Remove
	these data members.  They are now carried by decl_base::priv.
	(class_or_union::{g,s}et_alignment_in_bits): Adjust.
	(class_or_union::{g,s}et_size_in_bits): Likewise.
	(class_or_union::operator==): Likewise.
	(equals): Adjust the overload for class_or_union.
	(is_compatible_with_enum_type)
	* src/abg-comparison.cc (try_to_diff<class_decl>): Adjust the
	return type of decl_base::get_definition_of_declaration.
	(leaf_diff_node_marker_visitor::visit_begin): Use
	filtering::has_decl_only_def_change rather than
	filtering::has_class_decl_only_def_change.  Decl-only changes to
	enums (or any other type really) will thus not be recorded as leaf
	changes.
	* src/abg-dwarf-reader.cc (get_scope_for_die): Adjust return type
	of decl_base::get_definition_of_declaration.
	* src/abg-default-reporter.cc (default_reporter::report): Report
	enum decl-only <-> definition changes.
	* src/abg-hash.cc (class_or_union:#️⃣:operator()): In the
	overload for class_or_union& adjust the return type for
	decl_base::get_definition_of_declaration.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-07-08 16:59:56 +02:00

171 lines
4.5 KiB
C++

// -*- Mode: C++ -*-
//
// Copyright (C) 2013-2020 Red Hat, Inc.
//
// This file is part of the GNU Application Binary Interface Generic
// Analysis and Instrumentation Library (libabigail). This library is
// free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License as published by the
// Free Software Foundation; either version 3, or (at your option) any
// later version.
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this program; see the file COPYING-LGPLV3. If
// not, see <http://www.gnu.org/licenses/>.
//
// Author: Dodji Seketeli
/// @file
///
/// This header declares filters for the diff trees resulting from
/// comparing ABI Corpora.
#ifndef __ABG_COMP_FILTER_H__
#define __ABG_COMP_FILTER_H__
#include "abg-comparison.h"
namespace abigail
{
namespace comparison
{
/// Facilities to walk, categorize and possibly filter nodes of the
/// diff tree.
namespace filtering
{
bool
has_harmless_name_change(const decl_base_sptr& f, const decl_base_sptr& s);
bool union_diff_has_harmless_changes(const diff *d);
bool
has_harmful_name_change(const decl_base_sptr& f, const decl_base_sptr& s);
bool
has_harmful_name_change(const diff* dif);
bool
has_virtual_mem_fn_change(const function_decl_diff* diff);
bool
is_decl_only_class_with_size_change(const class_or_union& first,
const class_or_union& second);
bool
is_decl_only_class_with_size_change(const class_or_union_sptr& first,
const class_or_union_sptr& second);
bool
is_decl_only_class_with_size_change(const diff *diff);
bool
has_decl_only_def_change(const decl_base_sptr& first,
const decl_base_sptr& second);
bool
has_decl_only_def_change(const diff *d);
bool
has_class_decl_only_def_change(const class_or_union_sptr& first,
const class_or_union_sptr& second);
bool
has_enum_decl_only_def_change(const enum_type_decl_sptr& first,
const enum_type_decl_sptr& second);
bool
has_class_decl_only_def_change(const diff *diff);
bool
has_enum_decl_only_def_change(const diff *diff);
bool
has_basic_type_name_change(const diff *);
bool
has_class_or_union_type_name_change(const diff *d);
bool
has_basic_or_class_type_name_change(const diff *d);
bool
is_mostly_distinct_diff(const diff *d);
bool
has_anonymous_data_member_change(const diff *d);
bool
has_anonymous_data_member_change(const diff_sptr &d);
bool
has_data_member_replaced_by_anon_dm(const diff* diff);
struct filter_base;
/// Convenience typedef for a shared pointer to filter_base
typedef shared_ptr<filter_base> filter_base_sptr;
/// Convenience typedef for a vector of filter_base_sptr
typedef std::vector<filter_base_sptr> filters;
/// The base class for the diff tree node filter.
///
/// It's intended to walk a tree of diff nodes and tag each relevant
/// name into one or several categories depending on well choosen
/// properties of the diff nodes.
struct filter_base : public diff_node_visitor
{
friend void
apply_filter(filter_base_sptr f, diff_sptr deef);
}; //end class filter_base
void
apply_filter(filter_base& filter, diff_sptr d);
void
apply_filter(filter_base& filter, corpus_diff_sptr d);
void
apply_filter(filter_base_sptr filter, diff_sptr d);
class harmless_filter;
/// Convenience typedef for a shared pointer to a harmless_filter.
typedef shared_ptr<harmless_filter> harmless_filter_sptr;
/// A filter that walks the diff nodes tree and tags relevant diff
/// nodes into categories considered to represent harmless changes.
class harmless_filter : public filter_base
{
virtual bool
visit(diff*, bool);
virtual void
visit_end(diff*);
}; // end class harmless_filter
class harmless_harmful_filter;
/// A convenience typedef for a shared pointer to harmful_filter.
typedef shared_ptr<harmless_harmful_filter> harmful_harmless_filter_sptr;
/// A filter that walks the diff nodes tree and tags relevant diff
/// nodes into categories considered to represent potentially harmless
/// or harmful changes.
class harmless_harmful_filter : public filter_base
{
virtual bool
visit(diff*, bool);
virtual void
visit_end(diff*);
}; // end class harmless_harmful_filter
} // end namespace filtering
} // end namespace comparison
} // end namespace abigail
#endif // __ABG_COMP_FILTER_H__