From dc290415f19bcb60846e7bb8b7bb1c58e95ff3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Mon, 27 Mar 2017 21:38:56 +0200 Subject: [PATCH] Remove is_valid() for types Not complete and not really necessary. --- include/cppast/cpp_type.hpp | 4 -- src/cpp_type.cpp | 104 ----------------------------------- src/libclang/type_parser.cpp | 4 +- 3 files changed, 2 insertions(+), 110 deletions(-) diff --git a/include/cppast/cpp_type.hpp b/include/cppast/cpp_type.hpp index c207f8f..74a880f 100644 --- a/include/cppast/cpp_type.hpp +++ b/include/cppast/cpp_type.hpp @@ -70,10 +70,6 @@ namespace cppast friend detail::intrusive_list_node; }; - /// \returns `true` if the given [cppast::cpp_type]() is valid, `false` otherwise. - /// Invalid types are, for example, references to references. - bool is_valid(const cpp_type& type) noexcept; - /// An unexposed [cppast::cpp_type](). /// /// This is one where no further information besides a name is available. diff --git a/src/cpp_type.cpp b/src/cpp_type.cpp index 0214adb..9810256 100644 --- a/src/cpp_type.cpp +++ b/src/cpp_type.cpp @@ -30,107 +30,3 @@ std::unique_ptr cpp_dependent_type::build( return std::unique_ptr( new cpp_dependent_type(std::move(name), std::move(dependee))); } - -namespace -{ - bool can_compose(const cpp_type& type) - { - return type.kind() != cpp_type_kind::function - && type.kind() != cpp_type_kind::member_function - && type.kind() != cpp_type_kind::member_object; - } -} - -bool cppast::is_valid(const cpp_type& type) noexcept -{ - switch (type.kind()) - { - case cpp_type_kind::cv_qualified: - { - auto& qual = static_cast(type); - if (qual.type().kind() == cpp_type_kind::reference) - return false; // not allowed - return is_valid(qual.type()); - } - case cpp_type_kind::pointer: - { - auto& ptr = static_cast(type); - if (ptr.pointee().kind() == cpp_type_kind::reference) - return false; // not allowed - return is_valid(ptr.pointee()); - } - case cpp_type_kind::reference: - { - auto& ref = static_cast(type); - if (ref.referee().kind() == cpp_type_kind::member_function - || ref.referee().kind() == cpp_type_kind::member_object) - return false; // not allowed - return is_valid(ref.referee()); - } - - case cpp_type_kind::array: - { - auto& array = static_cast(type); - if (array.value_type().kind() == cpp_type_kind::reference - || !can_compose(array.value_type())) - return false; - return is_valid(array.value_type()); - } - - case cpp_type_kind::function: - { - auto& func = static_cast(type); - - if (!can_compose(func.return_type()) || !is_valid(func.return_type())) - return false; - - for (auto& arg : func.parameter_types()) - if (!can_compose(arg) || !is_valid(arg)) - return false; - - return true; - } - case cpp_type_kind::member_function: - { - auto& func = static_cast(type); - - if (!can_compose(func.class_type()) || !is_valid(func.class_type())) - return false; - else if (!can_compose(func.return_type()) || !is_valid(func.return_type())) - return false; - - for (auto& arg : func.parameter_types()) - if (!can_compose(arg) || !is_valid(arg)) - return false; - - return true; - } - case cpp_type_kind::member_object: - { - auto& obj = static_cast(type); - - if (obj.class_type().kind() != cpp_type_kind::user_defined) - return false; - return is_valid(obj.object_type()); - } - - case cpp_type_kind::dependent: - { - auto& dep = static_cast(type); - return is_valid(dep.dependee()); - } - - case cpp_type_kind::builtin: - case cpp_type_kind::user_defined: - case cpp_type_kind::auto_: - case cpp_type_kind::decltype_: - case cpp_type_kind::decltype_auto: - case cpp_type_kind::template_parameter: - case cpp_type_kind::template_instantiation: - case cpp_type_kind::unexposed: - // no further check required/possible - break; - } - - return true; -} diff --git a/src/libclang/type_parser.cpp b/src/libclang/type_parser.cpp index 4f3dd76..8d1a838 100644 --- a/src/libclang/type_parser.cpp +++ b/src/libclang/type_parser.cpp @@ -584,8 +584,8 @@ std::unique_ptr detail::parse_type(const detail::parse_context& contex const CXCursor& cur, const CXType& type) { auto result = parse_type_impl(context, cur, type); - DEBUG_ASSERT(result && is_valid(*result), detail::parse_error_handler{}, type, "invalid type"); - return std::move(result); + DEBUG_ASSERT(result != nullptr, detail::parse_error_handler{}, type, "invalid type"); + return result; } std::unique_ptr detail::parse_raw_type(const detail::parse_context&,