libabigail/include/abg-reporter.h
Dodji Seketeli 7535d74c3c Bug 29340 - Add support for Ada range types
Libabigail doesn't yet support generic range types like in Ada.
Ranges are supported as a kind of implementation detail of array
types.  But then its use like in the construct below is not supported:

    type My_Int is range 0 .. 5;
    function My_Function return My_Int;

Here, the integer type "My_Int" can take the discrete values that go
from 0 to 5.  It's represented in the DWARF debug info as being a
range type of length 6 and whose underlying type has a size of 8 bits.

This patch adds support for a range type to be (de-)serialized from
and to abixml, diffed, diff-analyzed and diff-reported.

The ABIXML version number has been bumped from 2.1 to 2.2 accordingly.

	* configure.ac: Bump the abixml version to 2.2 from 2.1
	* include/abg-comparison.h (diff_maps::get_subrange_diff_map):
	Declare new member functions.
	(class subrange_diff): Define new class.
	(subrange_diff_sptr): Define new typedef.
	(compute_diff): New overload for subrange_diff.
	(is_subrange_diff): Declare new function.
	* include/abg-ir.h (equals): Declare an overload for
	subrange_type.
	* include/abg-reporter.h (reporter_base::report): Declare an
	overload for subrange_diff.
	(default_reporter::report_underlying_changes_of_qualified_type):
	Declare member function.
	(leaf_reporter::report): Declare and overload for subrange_diff.
	Declare new member function.
	* include/abg-tools-utils.h
	(get_anonymous_subrange_internal_name_prefix): Declare new function.
	* src/abg-comparison-priv.h (struct subrange_diff::priv): Define
	new type.
	* src/abg-comparison.cc (diff_maps::priv::subrange_diff_map_):
	Define data member.
	(diff_maps::get_subrange_diff_map): Define member function.
	(is_subrange_diff, compute_diff): Define new functions.
	(compute_diff_for_types): Handle array_type::subrange_type types.
	(subrange_diff::{subrange_diff, first_subrange, second_subrange,
	get_pretty_representation, has_changes, has_local_changes, report,
	chain_into_hierarchy}): Define member functions.
	(diff_maps::insert_diff_node): Handle subrange diff nodes.
	(corpus_diff::priv::count_leaf_type_changes): Count subranges diff
	nodes.
	* src/abg-default-reporter.cc (default_reporter::report): Define
	an overload for subrange_diff.
	* src/abg-ir.cc (has_generic_anonymous_internal_type_name):
	Support subrange types.
	* src/abg-leaf-reporter.cc (report_type_changes_from_diff_maps):
	Report about subrange types.
	(leaf_reporter::report): Define and overload for subrange_diff
	nodes.
	* src/abg-reader.cc (build_subrange_type): Add a boolean to add
	the subrange type to the current scope.
	(build_array_type_def): Adjust when calling build_subrange_type.
	(build_type): Support building subrange types.
	* src/abg-reporter-priv.cc (represent): Define a new overload for
	the subrange_diff type.
	* src/abg-reporter-priv.h (represent): Declare a new overload for
	the subrange_diff type.
	* src/abg-tools-utils.cc (ANONYMOUS_SUBRANGE_INTERNAL_NAME)
	(ANONYMOUS_SUBRANGE_INTERNAL_NAME_LEN): Define new static const
	variables.
	(get_anonymous_subrange_internal_name_prefix): Define new
	function.
	* src/abg-writer.cc (write_array_subrange_type): Define new static
	function.
	(write_decl): Support emitting subrange_types.
	* tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-1.txt:
	New reference output.
	* tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-2.txt:
	Likewise.
	* tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/v0/test1.ad{b,s}:
	Source code of the input binary below.
	* tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/v0/test1.o:
	New input test.
	* tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/v1/test1.ad{b,s}:
	Source code of the input binary below.
	* tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/v1/test1.o:
	New input test.
	* tests/data/Makefile.am: Add the new test files to source
	distributions.
	* tests/test-abidiff-exit.cc (in_out_specs): Add the new tests
	input above to this test harness.
	* tests/data/test-annotate/PR29443-missing-xx.o.annotated.abi:
	Adjust.
	* tests/data/test-annotate/libtest23.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-annotate/test-anonymous-members-0.o.abi:
	Likewise.
	* tests/data/test-annotate/test0.abi: Likewise.
	* tests/data/test-annotate/test1.abi: Likewise.
	* tests/data/test-annotate/test13-pr18894.so.abi: Likewise.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-annotate/test2.so.abi: Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-annotate/test3.so.abi: Likewise.
	* tests/data/test-annotate/test4.so.abi: Likewise.
	* tests/data/test-annotate/test5.o.abi: Likewise.
	* tests/data/test-annotate/test6.so.abi: Likewise.
	* tests/data/test-annotate/test7.so.abi: Likewise.
	* tests/data/test-annotate/test8-qualified-this-pointer.so.abi:
	Likewise.
	* tests/data/test-read-btf/test0.o.abi: Likewise.
	* tests/data/test-read-btf/test1.o.abi: Likewise.
	* tests/data/test-read-ctf/PR27700/test-PR27700.abi: Likewise.
	* tests/data/test-read-ctf/test-PR26568-1.o.abi: Likewise.
	* tests/data/test-read-ctf/test-PR26568-2.o.abi: Likewise.
	* tests/data/test-read-ctf/test-alias.o.abi: Likewise.
	* tests/data/test-read-ctf/test-ambiguous-struct-A.o.hash.abi:
	Likewise.
	* tests/data/test-read-ctf/test-ambiguous-struct-B.o.hash.abi:
	Likewise.
	* tests/data/test-read-ctf/test-anonymous-fields.o.abi: Likewise.
	* tests/data/test-read-ctf/test-array-mdimension.abi: Likewise.
	* tests/data/test-read-ctf/test-array-of-pointers.abi: Likewise.
	* tests/data/test-read-ctf/test-array-size.abi: Likewise.
	* tests/data/test-read-ctf/test-bitfield-enum.abi: Likewise.
	* tests/data/test-read-ctf/test-bitfield.abi: Likewise.
	* tests/data/test-read-ctf/test-callback.abi: Likewise.
	* tests/data/test-read-ctf/test-callback2.abi: Likewise.
	* tests/data/test-read-ctf/test-conflicting-type-syms-a.o.hash.abi:
	Likewise.
	* tests/data/test-read-ctf/test-conflicting-type-syms-b.o.hash.abi:
	Likewise.
	* tests/data/test-read-ctf/test-const-array.abi: Likewise.
	* tests/data/test-read-ctf/test-dynamic-array.o.abi: Likewise.
	* tests/data/test-read-ctf/test-enum-many.o.hash.abi: Likewise.
	* tests/data/test-read-ctf/test-enum-symbol.o.hash.abi: Likewise.
	* tests/data/test-read-ctf/test-enum.o.abi: Likewise.
	* tests/data/test-read-ctf/test-fallback.abi: Likewise.
	* tests/data/test-read-ctf/test-forward-type-decl.abi: Likewise.
	* tests/data/test-read-ctf/test-functions-declaration.abi:
	Likewise.
	* tests/data/test-read-ctf/test-linux-module.abi: Likewise.
	* tests/data/test-read-ctf/test-list-struct.abi: Likewise.
	* tests/data/test-read-ctf/test0.abi: Likewise.
	* tests/data/test-read-ctf/test0.hash.abi: Likewise.
	* tests/data/test-read-ctf/test1.so.abi: Likewise.
	* tests/data/test-read-ctf/test1.so.hash.abi: Likewise.
	* tests/data/test-read-ctf/test2.so.abi: Likewise.
	* tests/data/test-read-ctf/test2.so.hash.abi: Likewise.
	* tests/data/test-read-ctf/test3.so.abi: Likewise.
	* tests/data/test-read-ctf/test3.so.hash.abi: Likewise.
	* tests/data/test-read-ctf/test4.so.abi: Likewise.
	* tests/data/test-read-ctf/test4.so.hash.abi: Likewise.
	* tests/data/test-read-ctf/test5.o.abi: Likewise.
	* tests/data/test-read-ctf/test7.o.abi: Likewise.
	* tests/data/test-read-ctf/test8.o.abi: Likewise.
	* tests/data/test-read-ctf/test9.o.abi: Likewise.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR24378-fn-is-not-scope.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Likewise.
	* tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR26261/PR26261-exe.abi: Likewise.
	* tests/data/test-read-dwarf/PR27700/test-PR27700.abi: Likewise.
	* tests/data/test-read-dwarf/PR28584/PR28584-smv.clang.o.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR29443-missing-xx.o.abi: Likewise.
	* tests/data/test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0.abi:
	Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-PR26568-1.o.abi: Likewise.
	* tests/data/test-read-dwarf/test-PR26568-2.o.abi: Likewise.
	* tests/data/test-read-dwarf/test-fallback.abi: Likewise.
	* tests/data/test-read-dwarf/test-libaaudio.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-suppressed-alias.o.abi:
	Likewise.
	* tests/data/test-read-dwarf/test0.abi: Likewise.
	* tests/data/test-read-dwarf/test0.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test1.abi: Likewise.
	* tests/data/test-read-dwarf/test1.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Likewise.
	* tests/data/test-read-dwarf/test11-pr18828.so.abi: Likewise.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise.
	* tests/data/test-read-dwarf/test13-pr18894.so.abi: Likewise.
	* tests/data/test-read-dwarf/test14-pr18893.so.abi: Likewise.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Likewise.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
	* tests/data/test-read-dwarf/test17-pr19027.so.abi: Likewise.
	* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test2.so.abi: Likewise.
	* tests/data/test-read-dwarf/test2.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test3-alias-1.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3-alias-2.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3-alias-3.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3-alias-4.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3.so.abi: Likewise.
	* tests/data/test-read-dwarf/test3.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test4.so.abi: Likewise.
	* tests/data/test-read-dwarf/test4.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test5.o.abi: Likewise.
	* tests/data/test-read-dwarf/test5.o.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test6.so.abi: Likewise.
	* tests/data/test-read-dwarf/test6.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test7.so.abi: Likewise.
	* tests/data/test-read-dwarf/test7.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test8-qualified-this-pointer.so.abi: Likewise.
	* tests/data/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.
	* tests/data/test-read-write/test-crc.xml: Likewise.
	* tests/data/test-read-write/test26.xml: Likewise.
	* tests/data/test-read-write/test27.xml: Likewise.
	* tests/data/test-read-write/test28-without-std-fns-ref.xml: Likewise.
	* tests/data/test-read-write/test28-without-std-vars-ref.xml:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2023-03-31 23:14:01 +02:00

351 lines
9.0 KiB
C++

// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- Mode: C++ -*-
//
// Copyright (C) 2017-2023 Red Hat, Inc.
//
// Author: Dodji Seketeli
/// @file
///
/// The declaration of the reporting types of libabigail's diff
/// engine.
#ifndef __ABG_REPORTER_H__
#define __ABG_REPORTER_H__
#include <memory>
#include <ostream>
#include <string>
namespace abigail
{
using std::shared_ptr;
namespace comparison
{
class diff;
class type_decl_diff;
class enum_diff;
class typedef_diff;
class qualified_type_diff;
class distinct_diff;
class pointer_diff;
class reference_diff;
class subrange_diff;
class array_diff;
class base_diff;
class class_or_union_diff;
class class_diff;
class union_diff;
class scope_diff;
class fn_parm_diff;
class function_type_diff;
class function_decl_diff;
class var_diff;
class translation_unit_diff;
class corpus_diff;
class diff_maps;
class reporter_base;
/// A convenience typedef for a shared pointer to a @ref
/// reporter_base.
typedef shared_ptr<reporter_base> reporter_base_sptr;
/// The base class of all the reporting classes.
class reporter_base
{
public:
virtual bool diff_to_be_reported(const diff *d) const;
virtual bool diff_has_net_changes(const corpus_diff *d) const = 0;
virtual void
report(const type_decl_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const enum_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const typedef_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const qualified_type_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const distinct_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const pointer_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const reference_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const array_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const subrange_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const base_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const class_or_union_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const class_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const union_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const scope_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const fn_parm_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const function_type_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const function_decl_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const var_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const translation_unit_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual void
report(const corpus_diff& d, std::ostream& out,
const std::string& indent = "") const = 0;
virtual ~reporter_base() {}
}; //end class reporter_base
class default_reporter;
/// A convenience typedef for a shared_ptr to a @ref default_reporter.
typedef shared_ptr<default_reporter> default_reporter_sptr;
/// The default, initial, reporter of the libabigail comparison engine.
class default_reporter : public reporter_base
{
public:
virtual bool diff_has_net_changes(const corpus_diff *d) const;
virtual void
report(const type_decl_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const enum_diff& d, std::ostream& out,
const std::string& indent = "") const;
void
report_non_type_typedef_changes(const typedef_diff &d,
std::ostream& out,
const std::string& indent) const;
virtual void
report(const typedef_diff& d, std::ostream& out,
const std::string& indent = "") const;
bool
report_local_qualified_type_changes(const qualified_type_diff& d,
std::ostream& out,
const std::string& indent) const;
void
report_underlying_changes_of_qualified_type (const qualified_type_diff& d,
ostream& out,
const string& indent) const;
virtual void
report(const qualified_type_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const pointer_diff& d, std::ostream& out,
const std::string& indent = "") const;
void
report_local_reference_type_changes(const reference_diff& d,
std::ostream& out,
const std::string& indent) const;
virtual void
report(const reference_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const fn_parm_diff& d, std::ostream& out,
const std::string& indent = "") const;
void
report_local_function_type_changes(const function_type_diff& d,
std::ostream& out,
const std::string& indent) const;
virtual void
report(const function_type_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const subrange_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const array_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const base_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const scope_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const class_or_union_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const class_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const union_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const distinct_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const function_decl_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const var_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const translation_unit_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const corpus_diff& d, std::ostream& out,
const std::string& indent = "") const;
}; // end class default_reporter
/// A reporter that only reports leaf changes
class leaf_reporter : public default_reporter
{
public:
virtual bool diff_to_be_reported(const diff *d) const;
virtual bool diff_has_net_changes(const corpus_diff *d) const;
void
report_changes_from_diff_maps(const diff_maps&, std::ostream& out,
const std::string& indent) const;
virtual void
report(const typedef_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const qualified_type_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const pointer_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const reference_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const fn_parm_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const function_type_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const subrange_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const array_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const scope_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const class_or_union_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const class_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const union_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const distinct_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const function_decl_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const var_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const translation_unit_diff& d, std::ostream& out,
const std::string& indent = "") const;
virtual void
report(const corpus_diff& d, std::ostream& out,
const std::string& indent = "") const;
}; // end class leaf_reporter
} // end namespace comparison
} // end namespace abigail
#endif // __ABG_REPORTER_H__