2013-10-11 15:19:29 +00:00
|
|
|
// -*- Mode: C++ -*-
|
|
|
|
//
|
|
|
|
// Copyright (C) 2013 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
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
#include "abg-comparison.h"
|
|
|
|
#include "abg-tools-utils.h"
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::ostream;
|
|
|
|
using std::cout;
|
|
|
|
using std::cerr;
|
|
|
|
using abigail::translation_unit;
|
|
|
|
using abigail::translation_unit_sptr;
|
Progress on diffing pointers, references and classes
* include/abg-comparison.h (diff::{first_subject,second_subject): Changed
first_scope/second_scope into these; so that this diff class now works on
stuff that are not scope. Changed the type of these to
decl_base_sptr
(diff::diff): Update for the change above.
(diff::{length, report}): New virtual pure methods.
(class pointer_diff, reference_diff): New classes declarations.
(compute_diff): New overloads for the new classes above. Make the
existing overloads take shared_pointers instead of references.
Also make them return shared pointers of the computed diff, rather
than just populating diff references passed in parameter.
(class class_diff): Renamed class class_decl_diff into this.
(report_changes): Change these functions into member functions.
* src/abg-comparison.cc (compute_diff_for_types): New static
function.
(pointer_diff::pointer_diff, pointer_diff::first_pointer)
(pointer_diff::second_pointer, pointer_diff::length)
(pointer_diff::underlying_type_diff)
(pointer_diff::underlying_type_diff, pointer_diff::report)
(pointer_diff::report, compute_diff)
(reference_diff::reference_diff, reference_diff::first_reference)
(reference_diff::second_reference)
(reference_diff::underlying_type_diff)
(reference_diff::underlying_type_diff, reference_diff::length)
(reference_diff::report, compute_diff): New functions.
(class_diff::class_diff, class_diff::length)
(class_diff::first_class_decl, class_diff::second_class_decl)
(class_diff::base_changes, class_diff::base_changes)
(class_diff::member_types_changes)
(class_diff::member_types_changes)
(class_diff::data_members_changes)
(class_diff::data_members_changes, class_diff::member_fns_changes)
(class_diff::member_fns_changes)
(class_diff::member_fn_tmpls_changes)
(class_diff::member_class_tmpls_changes)
Update wrt class_decl_diff -> class_diff renaming.
(class_diff::report): Make the report function be a member
function. Add an indentation parameter. Add support for member
types and data members.
(compute_diff): New overload for class_decl_sptr.
(scope_diff::first_scope, scope_diff::second_scope)
(scope_diff::length, scope_diff::report): New member functions.
(scope_diff::{deleted_member_at, inserted_member_at}): Update wrt
first_scope -> first_subject change.
(compute_diff): New overload for scope_decl_sptr.
(translation_unit_diff::report): Change the report function into
this member function.
(compute_diff): Change the overload for translation_unit to take a
translation_unit_sptr rather than a reference.
* tools/bidiff.cc (main): Update this wrt the change of the
signature of compute_diff.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-10-15 08:49:44 +00:00
|
|
|
using abigail::comparison::translation_unit_diff_sptr;
|
2013-10-11 15:19:29 +00:00
|
|
|
using abigail::comparison::compute_diff;
|
|
|
|
using abigail::tools::check_file;
|
|
|
|
|
|
|
|
struct options
|
|
|
|
{
|
|
|
|
string file1;
|
|
|
|
string file2;
|
|
|
|
};//end struct options;
|
|
|
|
|
|
|
|
void
|
|
|
|
display_usage(const string prog_name, ostream& out)
|
|
|
|
{
|
|
|
|
out << "usage: " << prog_name << "[options] [<bi-file1> <bi-file2>]\n"
|
|
|
|
<< " where options can be:\n"
|
|
|
|
<< " --help display this message\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Parse the command line and set the options accordingly.
|
|
|
|
///
|
|
|
|
/// @param argc the number of words on the command line
|
|
|
|
///
|
|
|
|
/// @param argv the command line, which is an array of words.
|
|
|
|
///
|
|
|
|
/// @param opts the options data structure. This is set by the
|
|
|
|
/// function iff it returns true.
|
|
|
|
///
|
|
|
|
/// @return true if the command line could be parsed and opts filed,
|
|
|
|
/// false otherwise.
|
|
|
|
bool
|
|
|
|
parse_command_line(int argc, char* argv[], options& opts)
|
|
|
|
{
|
|
|
|
if (argc < 2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (int i = 1; i < argc; ++i)
|
|
|
|
{
|
|
|
|
if (argv[i][0] != '-')
|
|
|
|
{
|
|
|
|
if (opts.file1.empty())
|
|
|
|
opts.file1 = argv[i];
|
|
|
|
else if (opts.file2.empty())
|
|
|
|
opts.file2 = argv[i];
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (!strcmp (argv[i], "--help"))
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
options opts;
|
|
|
|
if (!parse_command_line(argc, argv, opts))
|
|
|
|
{
|
|
|
|
display_usage(argv[0], cerr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!opts.file1.empty() && !opts.file2.empty())
|
|
|
|
{
|
|
|
|
if (!check_file(opts.file1, cerr))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!check_file(opts.file2, cerr))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
translation_unit_sptr t1(new translation_unit(opts.file1));
|
|
|
|
translation_unit_sptr t2(new translation_unit(opts.file2));
|
|
|
|
|
|
|
|
if (!t1->read())
|
|
|
|
{
|
|
|
|
cerr << "failed to read input file " << t1->get_path() << "\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!t2->read())
|
|
|
|
{
|
|
|
|
cerr << "failed to read input file" << t2->get_path() << "\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Progress on diffing pointers, references and classes
* include/abg-comparison.h (diff::{first_subject,second_subject): Changed
first_scope/second_scope into these; so that this diff class now works on
stuff that are not scope. Changed the type of these to
decl_base_sptr
(diff::diff): Update for the change above.
(diff::{length, report}): New virtual pure methods.
(class pointer_diff, reference_diff): New classes declarations.
(compute_diff): New overloads for the new classes above. Make the
existing overloads take shared_pointers instead of references.
Also make them return shared pointers of the computed diff, rather
than just populating diff references passed in parameter.
(class class_diff): Renamed class class_decl_diff into this.
(report_changes): Change these functions into member functions.
* src/abg-comparison.cc (compute_diff_for_types): New static
function.
(pointer_diff::pointer_diff, pointer_diff::first_pointer)
(pointer_diff::second_pointer, pointer_diff::length)
(pointer_diff::underlying_type_diff)
(pointer_diff::underlying_type_diff, pointer_diff::report)
(pointer_diff::report, compute_diff)
(reference_diff::reference_diff, reference_diff::first_reference)
(reference_diff::second_reference)
(reference_diff::underlying_type_diff)
(reference_diff::underlying_type_diff, reference_diff::length)
(reference_diff::report, compute_diff): New functions.
(class_diff::class_diff, class_diff::length)
(class_diff::first_class_decl, class_diff::second_class_decl)
(class_diff::base_changes, class_diff::base_changes)
(class_diff::member_types_changes)
(class_diff::member_types_changes)
(class_diff::data_members_changes)
(class_diff::data_members_changes, class_diff::member_fns_changes)
(class_diff::member_fns_changes)
(class_diff::member_fn_tmpls_changes)
(class_diff::member_class_tmpls_changes)
Update wrt class_decl_diff -> class_diff renaming.
(class_diff::report): Make the report function be a member
function. Add an indentation parameter. Add support for member
types and data members.
(compute_diff): New overload for class_decl_sptr.
(scope_diff::first_scope, scope_diff::second_scope)
(scope_diff::length, scope_diff::report): New member functions.
(scope_diff::{deleted_member_at, inserted_member_at}): Update wrt
first_scope -> first_subject change.
(compute_diff): New overload for scope_decl_sptr.
(translation_unit_diff::report): Change the report function into
this member function.
(compute_diff): Change the overload for translation_unit to take a
translation_unit_sptr rather than a reference.
* tools/bidiff.cc (main): Update this wrt the change of the
signature of compute_diff.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-10-15 08:49:44 +00:00
|
|
|
translation_unit_diff_sptr changes = compute_diff(t1, t2);
|
|
|
|
changes->report(cout);
|
2013-10-11 15:19:29 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|