Simplify interface for serializing/deserializing translation_units.
2013-08-06 Benjamin Kosnik <bkoz@redhat.com> * include/abg-ir.h (translation_unit::read): New member function. (translation_unit::write): Same. * src/abg-reader.cc (translation_unit::read): Define. * src/abg-writer.cc (translation_unit::write): Define. * include/abg-reader.h: Remove. * include/abg-writer.h: Remove. * include/Makefile.am (headers): Same. * include/Makefile.in: Regenerate.
This commit is contained in:
parent
32ce30a23c
commit
9c7f025ae9
|
@ -1,11 +1,9 @@
|
|||
headers = \
|
||||
abg-ir.h \
|
||||
abg-irfwd.h \
|
||||
abg-reader.h \
|
||||
abg-corpus.h \
|
||||
abg-libxml-utils.h \
|
||||
abg-hash.h \
|
||||
abg-writer.h \
|
||||
abg-config.h \
|
||||
abg-version.h \
|
||||
abg-viz-common.h \
|
||||
|
|
|
@ -209,11 +209,9 @@ top_srcdir = @top_srcdir@
|
|||
headers = \
|
||||
abg-ir.h \
|
||||
abg-irfwd.h \
|
||||
abg-reader.h \
|
||||
abg-corpus.h \
|
||||
abg-libxml-utils.h \
|
||||
abg-hash.h \
|
||||
abg-writer.h \
|
||||
abg-config.h \
|
||||
abg-version.h \
|
||||
abg-viz-common.h \
|
||||
|
|
|
@ -142,7 +142,7 @@ public:
|
|||
|
||||
/// Constructor of translation_unit.
|
||||
///
|
||||
/// @param path the path of the translation unit.
|
||||
/// @param path the location of the translation unit.
|
||||
translation_unit(const std::string& path);
|
||||
|
||||
/// @return the path of the compilation unit that gave birth to this
|
||||
|
@ -179,6 +179,18 @@ public:
|
|||
bool
|
||||
is_empty() const;
|
||||
|
||||
/// Deserialize the contents of the external file into this
|
||||
/// translation_unit object.
|
||||
bool
|
||||
read();
|
||||
|
||||
/// Serialize the contents of this translation unit object into an
|
||||
/// external file.
|
||||
///
|
||||
/// @param out the ostream output object.
|
||||
bool
|
||||
write(std::ostream& out);
|
||||
|
||||
/// This implements the traversable_base::traverse pure virtual
|
||||
/// function.
|
||||
///
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
// -*- 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/>.
|
||||
|
||||
/// @file
|
||||
|
||||
#ifndef __ABG_READER_H__
|
||||
#define __ABG_READER_H__
|
||||
|
||||
#include "abg-corpus.h"
|
||||
|
||||
namespace abigail
|
||||
{
|
||||
/// Namespace for reader.
|
||||
namespace reader
|
||||
{
|
||||
bool
|
||||
read_file(translation_unit& tu);
|
||||
}// end namespace reader
|
||||
}// end namespace abigail
|
||||
|
||||
#endif //__ABG_READER_H__
|
|
@ -1,39 +0,0 @@
|
|||
// -*- 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/>.
|
||||
|
||||
/// @file
|
||||
|
||||
#ifndef __ABG_WRITER_H__
|
||||
#define __ABG_WRITER_H__
|
||||
|
||||
#include <iosfwd>
|
||||
#include "abg-corpus.h"
|
||||
|
||||
namespace abigail
|
||||
{
|
||||
/// Namespace for writer.
|
||||
namespace writer
|
||||
{
|
||||
bool
|
||||
write_to_ostream(const translation_unit& tu, std::ostream& out);
|
||||
}//end namespace writer
|
||||
|
||||
}// end namespace abigail
|
||||
#endif //__ABG_WRITER_H__
|
|
@ -27,28 +27,28 @@
|
|||
#include <assert.h>
|
||||
#include <libxml/xmlstring.h>
|
||||
#include <libxml/xmlreader.h>
|
||||
#include "abg-reader.h"
|
||||
#include "abg-libxml-utils.h"
|
||||
|
||||
using std::string;
|
||||
using std::stack;
|
||||
using std::tr1::unordered_map;
|
||||
using std::tr1::dynamic_pointer_cast;
|
||||
using std::vector;
|
||||
#include "abg-ir.h"
|
||||
|
||||
namespace abigail
|
||||
{
|
||||
|
||||
using xml::xml_char_sptr;
|
||||
|
||||
/// Internal namespace for reader.
|
||||
namespace reader
|
||||
{
|
||||
using std::string;
|
||||
using std::stack;
|
||||
using std::tr1::unordered_map;
|
||||
using std::tr1::dynamic_pointer_cast;
|
||||
using std::vector;
|
||||
|
||||
class read_context;
|
||||
|
||||
static void update_read_context(read_context&);
|
||||
static void update_read_context(read_context&, xmlNodePtr);
|
||||
static void update_depth_info_of_read_context(read_context&, int);
|
||||
static void update_read_context(read_context&);
|
||||
static void update_read_context(read_context&, xmlNodePtr);
|
||||
static void update_depth_info_of_read_context(read_context&, int);
|
||||
|
||||
/// This abstracts the context in which the current ABI
|
||||
/// instrumentation dump is being de-serialized. It carries useful
|
||||
|
@ -485,14 +485,6 @@ static bool handle_class_decl(read_context&);
|
|||
static bool handle_function_template_decl(read_context&);
|
||||
static bool handle_class_template_decl(read_context&);
|
||||
|
||||
bool
|
||||
read_file(translation_unit& tu)
|
||||
{
|
||||
read_context read_ctxt(xml::new_reader_from_file(tu.get_path()));
|
||||
|
||||
return read_input(read_ctxt, tu);
|
||||
}
|
||||
|
||||
/// Updates the instance of read_context. Basically update thee path
|
||||
/// of elements from the root to the current element, that we maintain
|
||||
/// to know the current scope. This function needs to be called after
|
||||
|
@ -2622,4 +2614,13 @@ handle_class_template_decl(read_context& ctxt)
|
|||
}
|
||||
|
||||
}//end namespace reader
|
||||
|
||||
|
||||
// Define reader.
|
||||
bool
|
||||
translation_unit::read()
|
||||
{
|
||||
reader::read_context read_ctxt(xml::new_reader_from_file(this->get_path()));
|
||||
return reader::read_input(read_ctxt, *this);
|
||||
}
|
||||
}//end namespace abigail
|
||||
|
|
|
@ -24,12 +24,12 @@
|
|||
#include <sstream>
|
||||
#include <tr1/memory>
|
||||
#include <tr1/unordered_map>
|
||||
#include "abg-writer.h"
|
||||
#include "abg-config.h"
|
||||
|
||||
#include "abg-ir.h"
|
||||
|
||||
namespace abigail
|
||||
{
|
||||
/// Internal namespace for writer.
|
||||
namespace writer
|
||||
{
|
||||
using std::tr1::shared_ptr;
|
||||
|
@ -67,7 +67,7 @@ public:
|
|||
string
|
||||
get_id_with_prefix(const string& prefix)
|
||||
{
|
||||
ostringstream o;
|
||||
ostringstream o;
|
||||
o << prefix << get_new_id();
|
||||
return o.str();
|
||||
}
|
||||
|
@ -173,8 +173,7 @@ private:
|
|||
}; //end write_context
|
||||
|
||||
static bool write_translation_unit(const translation_unit&,
|
||||
write_context&,
|
||||
unsigned);
|
||||
write_context&, unsigned);
|
||||
static void write_location(location, translation_unit&, ostream&);
|
||||
static void write_location(const shared_ptr<decl_base>&, ostream&);
|
||||
static bool write_visibility(const shared_ptr<decl_base>&, ostream&);
|
||||
|
@ -272,20 +271,6 @@ get_indent_to_level(write_context& ctxt, unsigned initial_indent,
|
|||
return nb_ws;
|
||||
}
|
||||
|
||||
/// Serialize a translation_unit into an output stream.
|
||||
///
|
||||
/// @param tu the translation unit to serialize.
|
||||
///
|
||||
/// @param out the output stream.
|
||||
///
|
||||
/// @return true upon successful completion, false otherwise.
|
||||
bool
|
||||
write_to_ostream(const translation_unit& tu, ostream &out)
|
||||
{
|
||||
write_context ctxt(out);
|
||||
return write_translation_unit(tu, ctxt, /*indent=*/0);
|
||||
}
|
||||
|
||||
/// Write a location to the output stream.
|
||||
///
|
||||
/// If the location is empty, nothing is written.
|
||||
|
@ -606,7 +591,7 @@ write_decl(const shared_ptr<decl_base> decl, write_context& ctxt,
|
|||
/// serialization.
|
||||
///
|
||||
/// @return true upon successful completion, false otherwise.
|
||||
static bool
|
||||
bool
|
||||
write_translation_unit(const translation_unit& tu, write_context& ctxt,
|
||||
unsigned indent)
|
||||
{
|
||||
|
@ -1505,5 +1490,13 @@ write_class_template_decl (const shared_ptr<class_template_decl> decl,
|
|||
return true;
|
||||
}
|
||||
|
||||
}//end namespace writer
|
||||
}//end namespace abigail
|
||||
} //end namespace writer
|
||||
|
||||
bool
|
||||
translation_unit::write(std::ostream &out)
|
||||
{
|
||||
writer::write_context ctxt(out);
|
||||
return writer::write_translation_unit(*this, ctxt, /*indent=*/0);
|
||||
}
|
||||
|
||||
} //end namespace abigail
|
||||
|
|
|
@ -22,13 +22,11 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include "abg-ir.h"
|
||||
#include "test-utils.h"
|
||||
#include "abg-reader.h"
|
||||
#include "abg-writer.h"
|
||||
|
||||
using std::string;
|
||||
using std::ofstream;
|
||||
|
||||
using std::cerr;
|
||||
|
||||
/// This is an aggregate that specifies where a test shall get its
|
||||
|
@ -143,8 +141,8 @@ main()
|
|||
{
|
||||
string input_suffix(s->in_path);
|
||||
in_path = abigail::tests::get_src_dir() + "/tests/" + input_suffix;
|
||||
abigail::translation_unit tu(input_suffix);
|
||||
if (!abigail::reader::read_file(tu))
|
||||
abigail::translation_unit tu(in_path);
|
||||
if (!tu.read())
|
||||
{
|
||||
cerr << "failed to read " << in_path << "\n";
|
||||
is_ok = false;
|
||||
|
@ -168,7 +166,7 @@ main()
|
|||
continue;
|
||||
}
|
||||
|
||||
bool r = abigail::writer::write_to_ostream(tu, of);
|
||||
bool r = tu.write(of);
|
||||
is_ok = (is_ok && r);
|
||||
of.close();
|
||||
string cmd = "diff -u " + in_path + " " + out_path;
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include "abg-ir.h"
|
||||
#include "test-utils.h"
|
||||
#include "abg-reader.h"
|
||||
|
||||
using std::string;
|
||||
using std::ofstream;
|
||||
|
@ -50,7 +50,7 @@ main(int argc, char **argv)
|
|||
string file_name = argv[1];
|
||||
|
||||
abigail::translation_unit tu(file_name);
|
||||
if (!abigail::reader::read_file(tu))
|
||||
if (!tu.read())
|
||||
{
|
||||
cerr << "failed to read " << file_name << "\n";
|
||||
return 1;
|
||||
|
|
Loading…
Reference in New Issue