Remove is_valid() for types
Not complete and not really necessary.
This commit is contained in:
parent
6f050bac66
commit
dc290415f1
3 changed files with 2 additions and 110 deletions
|
|
@ -70,10 +70,6 @@ namespace cppast
|
||||||
friend detail::intrusive_list_node<cpp_type>;
|
friend detail::intrusive_list_node<cpp_type>;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \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]().
|
/// An unexposed [cppast::cpp_type]().
|
||||||
///
|
///
|
||||||
/// This is one where no further information besides a name is available.
|
/// This is one where no further information besides a name is available.
|
||||||
|
|
|
||||||
104
src/cpp_type.cpp
104
src/cpp_type.cpp
|
|
@ -30,107 +30,3 @@ std::unique_ptr<cpp_dependent_type> cpp_dependent_type::build(
|
||||||
return std::unique_ptr<cpp_dependent_type>(
|
return std::unique_ptr<cpp_dependent_type>(
|
||||||
new cpp_dependent_type(std::move(name), std::move(dependee)));
|
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<const cpp_cv_qualified_type&>(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<const cpp_pointer_type&>(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<const cpp_reference_type&>(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<const cpp_array_type&>(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<const cpp_function_type&>(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<const cpp_member_function_type&>(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<const cpp_member_object_type&>(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<const cpp_dependent_type&>(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;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -584,8 +584,8 @@ std::unique_ptr<cpp_type> detail::parse_type(const detail::parse_context& contex
|
||||||
const CXCursor& cur, const CXType& type)
|
const CXCursor& cur, const CXType& type)
|
||||||
{
|
{
|
||||||
auto result = parse_type_impl(context, cur, type);
|
auto result = parse_type_impl(context, cur, type);
|
||||||
DEBUG_ASSERT(result && is_valid(*result), detail::parse_error_handler{}, type, "invalid type");
|
DEBUG_ASSERT(result != nullptr, detail::parse_error_handler{}, type, "invalid type");
|
||||||
return std::move(result);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<cpp_type> detail::parse_raw_type(const detail::parse_context&,
|
std::unique_ptr<cpp_type> detail::parse_raw_type(const detail::parse_context&,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue