From 6c100a88b533dbf25c89ae976b8564754f3e1954 Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Nov 03 2016 14:12:46 +0000 Subject: Cleanup void and variadic parameter type interfaces While working on something else, it appeared that renaming abigail::environment::get_void_type_decl() to abigail::environment::get_void_type() and abigail::environment::get_variadic_parameter_type_decl() to abigail::environment::get_variadic_parameter_type() would be an improvement. This patch implements that. * include/abg-ir.h (environment::{get_void_type, get_variadic_parameter_type}): Renamed get_void_type_decl and get_variadic_parameter_type_decl to these. (environment::is_void_type): Remove the overload that takes a bare pointer. (environment::is_variadic_parameter_type): Declare new member function. * src/abg-ir.cc (environment::void_type_): Renamed the data member void_type_decl_ into this. (environment::variadic_marker_type_): Renamed the data member variadic_marker_type_decl_ into this. (environment::{get_void_type, get_variadic_parameter_type}): Renamed get_void_type_decl and get_variadic_parameter_type_decl to these. (environment::is_void_type): Take a smart pointer now. (environment::is_variadic_parameter_type): Define new member function. (synthesize_function_type_from_translation_unit): Adjust. (function_decl::parameter::get_pretty_representation): Likewise. * src/abg-comparison.cc (is_diff_of_variadic_parameter_type): Adjust. * src/abg-dwarf-reader.cc (build_function_type) (build_ir_node_for_void_type): Likewise. * src/abg-reader.cc (build_function_parameter) (build_function_decl, build_function_type): Likewise. Signed-off-by: Dodji Seketeli --- diff --git a/include/abg-ir.h b/include/abg-ir.h index 945c2fa..fd32029 100644 --- a/include/abg-ir.h +++ b/include/abg-ir.h @@ -160,11 +160,11 @@ public: canonical_types_map_type& get_canonical_types_map(); - const type_decl_sptr& - get_void_type_decl() const; + const type_base_sptr& + get_void_type() const; - const type_decl_sptr& - get_variadic_parameter_type_decl() const; + const type_base_sptr& + get_variadic_parameter_type() const; bool canonicalization_is_done() const; @@ -173,13 +173,13 @@ public: canonicalization_is_done(bool); bool - is_void_type(const type_decl*) const; + is_void_type(const type_base_sptr&) const; bool - is_void_type(const type_decl_sptr&) const; + is_variadic_parameter_type(const type_base*) const; bool - is_void_type(const type_base_sptr&) const; + is_variadic_parameter_type(const type_base_sptr&) const; interned_string intern(const string&) const; diff --git a/src/abg-comparison.cc b/src/abg-comparison.cc index 94d830c..f2acb25 100644 --- a/src/abg-comparison.cc +++ b/src/abg-comparison.cc @@ -13067,15 +13067,11 @@ is_diff_of_variadic_parameter_type(const diff* d) return false; type_base_sptr t = is_type(d->first_subject()); - if (t - && (t.get() - == t->get_environment()->get_variadic_parameter_type_decl().get())) + if (t && t->get_environment()->is_variadic_parameter_type(t)) return true; t = is_type(d->second_subject()); - if (t - && (t.get() - == t->get_environment()->get_variadic_parameter_type_decl().get())) + if (t && t->get_environment()->is_variadic_parameter_type(t)) return true; return false; diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index c2f08cd..a7a32a7 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -8506,7 +8506,7 @@ build_function_type(read_context& ctxt, bool is_artificial = die_is_artificial(&child); ir::environment* env = ctxt.env(); assert(env); - type_decl_sptr parm_type = env->get_variadic_parameter_type_decl(); + type_base_sptr parm_type = env->get_variadic_parameter_type(); function_decl::parameter_sptr p (new function_decl::parameter(parm_type, /*name=*/"", @@ -9762,11 +9762,13 @@ build_ir_node_for_void_type(read_context& ctxt) { ir::environment* env = ctxt.env(); assert(env); - decl_base_sptr t = env->get_void_type_decl(); - if (!has_scope(t)) - add_decl_to_scope(t, ctxt.cur_transl_unit()->get_global_scope()); - canonicalize(is_type(t)); - return t; + type_base_sptr t = env->get_void_type(); + decl_base_sptr type_declaration = get_type_declaration(t); + if (!has_scope(type_declaration)) + add_decl_to_scope(type_declaration, + ctxt.cur_transl_unit()->get_global_scope()); + canonicalize(t); + return type_declaration; } /// Build an IR node from a given DIE and add the node to the current diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 1df57cd..489fffd 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -2049,8 +2049,8 @@ struct environment::priv { bool canonicalization_is_done_; canonical_types_map_type canonical_types_; - type_decl_sptr void_type_decl_; - type_decl_sptr variadic_marker_type_decl_; + type_base_sptr void_type_; + type_base_sptr variadic_marker_type_; interned_string_set_type classes_being_compared_; interned_string_set_type fn_types_being_compared_; vector extra_live_types_; @@ -2082,14 +2082,14 @@ environment::get_canonical_types_map() /// environment. /// /// @return the @ref type_decl that represents a "void" type. -const type_decl_sptr& -environment::get_void_type_decl() const +const type_base_sptr& +environment::get_void_type() const { - if (!priv_->void_type_decl_) - priv_->void_type_decl_.reset(new type_decl(const_cast(this), + if (!priv_->void_type_) + priv_->void_type_.reset(new type_decl(const_cast(this), intern("void"), 0, 0, location())); - return priv_->void_type_decl_; + return priv_->void_type_; } /// Get a @ref type_decl instance that represents a the type of a @@ -2097,15 +2097,15 @@ environment::get_void_type_decl() const /// /// @return the Get a @ref type_decl instance that represents a the /// type of a variadic function parameter. -const type_decl_sptr& -environment::get_variadic_parameter_type_decl() const +const type_base_sptr& +environment::get_variadic_parameter_type() const { - if (!priv_->variadic_marker_type_decl_) - priv_->variadic_marker_type_decl_. + if (!priv_->variadic_marker_type_) + priv_->variadic_marker_type_. reset(new type_decl(const_cast(this), intern("variadic parameter type"), 0, 0, location())); - return priv_->variadic_marker_type_decl_; + return priv_->variadic_marker_type_; } /// Test if the canonicalization of types created out of the current @@ -2131,43 +2131,47 @@ void environment::canonicalization_is_done(bool f) {priv_->canonicalization_is_done_ = f;} -/// Test if a given basic type is a void type as defined in the -/// current environment. + +/// Test if a given type is a void type as defined in the current +/// environment. /// -/// @param d the basic type to consider. +/// @param t the type to consider. /// -/// @return true iff @p d is a void type as defined in the current +/// @return true iff @p t is a void type as defined in the current /// environment. bool -environment::is_void_type(const type_decl* d) const -{return (get_void_type_decl().get() == d);} +environment::is_void_type(const type_base_sptr& t) const +{ + if (!t) + return false; + return t.get() == get_void_type().get(); +} -/// Test if a given basic type is a void type as defined in the +/// Test if a type is a variadic parameter type as defined in the /// current environment. /// -/// @param d the basic type to consider. +/// @param t the type to consider. /// -/// @return true iff @p d is a void type as defined in the current -/// environment. +/// @return true iff @p t is a variadic parameter type as defined in +/// the current environment. bool -environment::is_void_type(const type_base_sptr& t) const +environment::is_variadic_parameter_type(const type_base* t) const { - type_decl_sptr d = is_type_decl(t); - if (!d) + if (!t) return false; - return is_void_type(d); + return t == get_variadic_parameter_type().get(); } -/// Test if a given basic type is a void type as defined in the +/// Test if a type is a variadic parameter type as defined in the /// current environment. /// -/// @param d the basic type to consider. +/// @param t the type to consider. /// -/// @return true iff @p d is a void type as defined in the current -/// environment. +/// @return true iff @p t is a variadic parameter type as defined in +/// the current environment. bool -environment::is_void_type(const type_decl_sptr& d) const -{return is_void_type(d.get());} +environment::is_variadic_parameter_type(const type_base_sptr& t) const +{return is_variadic_parameter_type(t.get());} /// Do intern a string. /// @@ -6475,9 +6479,8 @@ synthesize_function_type_from_translation_unit(const function_type& fn_type, type_base_sptr return_type = fn_type.get_return_type(); type_base_sptr result_return_type; - if (!return_type - || return_type.get() == env->get_void_type_decl().get()) - result_return_type = type_base_sptr(env->get_void_type_decl()); + if (!return_type || env->is_void_type(return_type)) + result_return_type = env->get_void_type(); else result_return_type = synthesize_type_from_translation_unit(return_type, tu); if (!result_return_type) @@ -6915,7 +6918,7 @@ type_or_void(const type_base_sptr t, const environment* env) else { assert(env); - r = type_base_sptr(env->get_void_type_decl()); + r = type_base_sptr(env->get_void_type()); } return r; @@ -12195,7 +12198,7 @@ function_decl::parameter::get_pretty_representation(bool internal) const type_base_sptr t = get_type(); if (!t) type_repr = "void"; - else if (env->get_variadic_parameter_type_decl()) + else if (env->is_variadic_parameter_type(t)) type_repr = "..."; else type_repr = ir::get_pretty_representation(t, internal); diff --git a/src/abg-reader.cc b/src/abg-reader.cc index d406300..df1501c 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -2604,7 +2604,7 @@ build_function_parameter(read_context& ctxt, const xmlNodePtr node) type_base_sptr type; if (is_variadic) - type = ctxt.get_environment()->get_variadic_parameter_type_decl(); + type = ctxt.get_environment()->get_variadic_parameter_type(); else { assert(!type_id.empty()); @@ -2684,7 +2684,7 @@ build_function_decl(read_context& ctxt, environment* env = ctxt.get_environment(); assert(env); std::vector parms; - type_base_sptr return_type = env->get_void_type_decl(); + type_base_sptr return_type = env->get_void_type(); for (xmlNodePtr n = node->children; n ; n = n->next) { @@ -3353,7 +3353,7 @@ build_function_type(read_context& ctxt, environment* env = ctxt.get_environment(); assert(env); std::vector > parms; - type_base_sptr return_type = env->get_void_type_decl();; + type_base_sptr return_type = env->get_void_type();; function_type_sptr fn_type(new function_type(return_type, parms, size, align));