mirror of
git://sourceware.org/git/libabigail.git
synced 2024-12-17 15:34:34 +00:00
ccdc44b3eb
This patch creates per-corpus maps that associate, for a certain kind of type, the fully qualified name of the type to the type. So there is a map for class_decl, one for enum_type_decl, one for type_decl, etc. These maps are populated when a new type is added to its scope. The patch defines overloads of the function maybe_update_types_lookup_map() that update the right map, depending on the kind of type we are looking at. Note that there also is a map in each class that associates a signature string to a member functions. This is so that member functions of a given class can be looked up by signature. This is so that looking up a type becomes now much faster than having to walk all the translation units of a corpus to find one. Note that this patch is specifically part of the series of patches that implements types and declarations de-duplication while reading DWARF information. The patch might slightly change the output of abi serialization or comparison so it needs some adjustments of some test reference files. That adjustment is not done here. Rather, it's done at once in another patch of the set. * include/abg-corpus.h (corpus::priv_): Make this public so that functions from outside of the class can access it. These functions are meant to be used only by code that is *inside* libabigail.so, though. * src/abg-corpus-priv.h: New file. * src/abg-corpus.cc: Include the new abg-corpus-priv.h file. (struct regex_t_deleter): Move this to abg-sptr-utils.h. (build_sptr<regex_t>): Move the declaration of this function template specialization to abg-sptr-utils.h and its definition to abg-sptr-utils.cc. (typedef regex_t_sptrs_type, typedef str_var_ptr_map_type) (struct corpus::exported_decls_builder::priv, struct corpus::priv): Move these declarations to the new abg-corpus-priv.h. (maybe_update_types_lookup_map): Define overloads of this (one per kind of type). (lookup_{basic, class, enum, typedef, class_or_typedef, class_typedef_or_enum, qualified, pointer, reference, array, function}_type): Define new functions. * include/abg-ir.h (typedef istring_type_base_wptr_map_type) (typedef istring_type_or_decl_base_sptr_map_type): Declare new typedefs. (class_decl::find_member_function_from_signature): Declare new member function. * src/abg-ir.cc: Include the new abg-corpus-priv.h file. (maybe_update_types_lookup_map): Remove this initial function. There are now new overloads in abg-corpus.cc for it. (scope_decl::{add_member_decl, insert_member_decl}): Adjust. (class_decl::{set_is_declaration_only, find_member_function, add_member_function}): Adjust. (class_decl::find_member_function_from_signature): Define new member function. * include/abg-sptr-utils.h (struct regex_t_deleter): Declare new type. (build_sptr<regex_t>): New build function template specializations. * src/abg-sptr-utils.cc: New file. * src/Makefile.am: Add src/abg-sptr-utils.cc and src/abg-corpus-priv.h to the build system. Signed-off-by: Dodji Seketeli <dodji@redhat.com>
144 lines
3.8 KiB
C++
144 lines
3.8 KiB
C++
// -*- mode: C++ -*-
|
|
//
|
|
// Copyright (C) 2013-2016 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
|
|
///
|
|
/// Utilities to ease the wrapping of C types into std::tr1::shared_ptr
|
|
|
|
#ifndef __ABG_SPTR_UTILS_H__
|
|
#define __ABG_SPTR_UTILS_H__
|
|
|
|
#include <tr1/memory>
|
|
#include <regex.h>
|
|
#include <libxml/xmlreader.h>
|
|
|
|
namespace abigail
|
|
{
|
|
|
|
/// Namespace for the utilities to wrap C types into std::tr1::shared_ptr.
|
|
namespace sptr_utils
|
|
{
|
|
|
|
using std::tr1::shared_ptr;
|
|
|
|
/// This is to be specialized for the diverse C types that needs
|
|
/// wrapping in shared_ptr.
|
|
///
|
|
/// @tparam T the type of the C type to wrap in a shared_ptr.
|
|
///
|
|
/// @param p a pointer to wrap in a shared_ptr.
|
|
///
|
|
/// @return then newly created shared_ptr<T>
|
|
template<class T>
|
|
shared_ptr<T>
|
|
build_sptr(T* p);
|
|
|
|
/// This is to be specialized for the diverse C types that needs
|
|
/// wrapping in shared_ptr.
|
|
///
|
|
/// This variant creates a pointer to T and wraps it into a
|
|
/// shared_ptr<T>.
|
|
///
|
|
/// @tparam T the type of the C type to wrap in a shared_ptr.
|
|
///
|
|
/// @return then newly created shared_ptr<T>
|
|
template<class T>
|
|
shared_ptr<T>
|
|
build_sptr();
|
|
|
|
/// A convenience typedef for a shared pointer of xmlTextReader.
|
|
typedef shared_ptr<xmlTextReader> reader_sptr;
|
|
|
|
/// Specialization of sptr_utils::build_sptr for xmlTextReader
|
|
template<>
|
|
reader_sptr
|
|
build_sptr<xmlTextReader>(xmlTextReader *p);
|
|
|
|
/// A convenience typedef for a shared pointer of xmlChar.
|
|
typedef shared_ptr<xmlChar> xml_char_sptr;
|
|
|
|
/// Specialization of build_str for xmlChar.
|
|
template<>
|
|
xml_char_sptr build_sptr<xmlChar>(xmlChar *p);
|
|
|
|
/// A convenience typedef for a shared pointer of regex_t.
|
|
typedef shared_ptr<regex_t> regex_t_sptr;
|
|
|
|
/// Specialization of sptr_utils::build_sptr for regex_t.
|
|
template<>
|
|
regex_t_sptr
|
|
build_sptr<regex_t>(regex_t *p);
|
|
|
|
/// Specialization of sptr_utils::build_sptr for regex_t.
|
|
template<>
|
|
regex_t_sptr
|
|
build_sptr<regex_t>();
|
|
|
|
/// A deleter for shared pointers that ... doesn't delete the object
|
|
/// managed by the shared pointer.
|
|
struct noop_deleter
|
|
{
|
|
template<typename T>
|
|
void
|
|
operator()(const T*)
|
|
{}
|
|
};
|
|
|
|
/// A delete functor for a shared_ptr of regex_t.
|
|
struct regex_t_deleter
|
|
{
|
|
/// The operator called to de-allocate the pointer to regex_t
|
|
/// embedded in a shared_ptr<regex_t>
|
|
///
|
|
/// @param r the pointer to regex_t to de-allocate.
|
|
void
|
|
operator()(::regex_t* r)
|
|
{
|
|
regfree(r);
|
|
delete r;
|
|
}
|
|
};//end struct regex_deleter
|
|
|
|
/// Specialization of sptr_utils::build_sptr for regex_t.
|
|
///
|
|
/// This is used to wrap a pointer to regex_t into a
|
|
/// shared_ptr<regex_t>.
|
|
///
|
|
/// @param p the bare pointer to regex_t to wrap into a shared_ptr<regex_t>.
|
|
///
|
|
/// @return the shared_ptr<regex_t> that wraps @p p.
|
|
template<>
|
|
regex_t_sptr
|
|
build_sptr<regex_t>(regex_t *p);
|
|
|
|
/// Specialization of sptr_utils::build_sptr for regex_t.
|
|
///
|
|
/// This creates a pointer to regex_t and wraps it into a shared_ptr<regex_t>.
|
|
///
|
|
/// @return the shared_ptr<regex_t> wrapping the newly created regex_t*
|
|
template<>
|
|
regex_t_sptr
|
|
build_sptr<regex_t>();
|
|
|
|
}// end namespace sptr_utils
|
|
}// end namespace abigail
|
|
|
|
#endif //__ABG_SPTR_UTILS_H__
|