Add and parse cpp_decltype_type
This commit is contained in:
parent
acb2f06bfd
commit
6f050bac66
9 changed files with 174 additions and 16 deletions
|
|
@ -3,7 +3,9 @@
|
|||
// found in the top-level directory of this distribution.
|
||||
|
||||
#include <cppast/cpp_function.hpp>
|
||||
|
||||
#include <cppast/cpp_array_type.hpp>
|
||||
#include <cppast/cpp_decltype_type.hpp>
|
||||
|
||||
#include "test_parser.hpp"
|
||||
|
||||
|
|
@ -15,7 +17,7 @@ TEST_CASE("cpp_function")
|
|||
// parameters and return type are only tested here
|
||||
void a();
|
||||
int b(int a, float* b = nullptr);
|
||||
int (&c(int a, ...))[10];
|
||||
int (&c(decltype(42) a, ...))[10];
|
||||
|
||||
// noexcept conditions
|
||||
void d() noexcept;
|
||||
|
|
@ -115,7 +117,12 @@ void ns::l()
|
|||
{
|
||||
if (param.name() == "a")
|
||||
{
|
||||
REQUIRE(equal_types(idx, param.type(), *cpp_builtin_type::build("int")));
|
||||
REQUIRE(
|
||||
equal_types(idx, param.type(),
|
||||
*cpp_decltype_type::build(
|
||||
cpp_literal_expression::build(cpp_builtin_type::build(
|
||||
"int"),
|
||||
"42"))));
|
||||
REQUIRE(!param.default_value());
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <cppast/cpp_type_alias.hpp>
|
||||
|
||||
#include <cppast/cpp_array_type.hpp>
|
||||
#include <cppast/cpp_decltype_type.hpp>
|
||||
#include <cppast/cpp_function_type.hpp>
|
||||
#include <cppast/cpp_template.hpp>
|
||||
#include <cppast/cpp_template_parameter.hpp>
|
||||
|
|
@ -33,6 +34,11 @@ bool equal_types(const cpp_entity_index& idx, const cpp_type& parsed, const cpp_
|
|||
|
||||
case cpp_type_kind::auto_:
|
||||
return true;
|
||||
case cpp_type_kind::decltype_:
|
||||
return equal_expressions(static_cast<const cpp_decltype_type&>(parsed).expression(),
|
||||
static_cast<const cpp_decltype_type&>(synthesized).expression());
|
||||
case cpp_type_kind::decltype_auto:
|
||||
return true;
|
||||
|
||||
case cpp_type_kind::cv_qualified:
|
||||
{
|
||||
|
|
@ -233,6 +239,9 @@ using s = int(foo::*);
|
|||
using t = struct t_ {};
|
||||
using u = const struct u_ {}*;
|
||||
using v = struct {};
|
||||
|
||||
// decltype
|
||||
using w = decltype(0);
|
||||
)";
|
||||
}
|
||||
SECTION("typedef")
|
||||
|
|
@ -279,6 +288,9 @@ typedef int(foo::*s);
|
|||
typedef struct t_ {} t;
|
||||
typedef const struct u_ {}* u;
|
||||
typedef struct {} v;
|
||||
|
||||
// decltype
|
||||
typedef decltype(0) w;
|
||||
)";
|
||||
}
|
||||
|
||||
|
|
@ -456,8 +468,14 @@ typedef struct {} v;
|
|||
auto type = cpp_user_defined_type::build(cpp_type_ref(cpp_entity_id(""), "v"));
|
||||
REQUIRE(equal_types(idx, alias.underlying_type(), *type));
|
||||
}
|
||||
else if (alias.name() == "w")
|
||||
{
|
||||
auto type = cpp_decltype_type::build(
|
||||
cpp_literal_expression::build(cpp_builtin_type::build("int"), "0"));
|
||||
REQUIRE(equal_types(idx, alias.underlying_type(), *type));
|
||||
}
|
||||
else
|
||||
REQUIRE(false);
|
||||
});
|
||||
REQUIRE(count == 22u);
|
||||
REQUIRE(count == 23u);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <cppast/cpp_variable.hpp>
|
||||
|
||||
#include <cppast/cpp_decltype_type.hpp>
|
||||
|
||||
#include "test_parser.hpp"
|
||||
|
||||
using namespace cppast;
|
||||
|
|
@ -34,6 +36,10 @@ static struct {} l;
|
|||
// auto
|
||||
auto m = 128;
|
||||
const auto& n = m;
|
||||
|
||||
// decltype
|
||||
decltype(0) o;
|
||||
const decltype(o)& p = o;
|
||||
)";
|
||||
|
||||
cpp_entity_index idx;
|
||||
|
|
@ -141,10 +147,28 @@ const auto& n = m;
|
|||
*cpp_unexposed_expression::build(cpp_builtin_type::build("int"),
|
||||
"m")),
|
||||
cpp_storage_class_none, false, false);
|
||||
else if (var.name() == "o")
|
||||
check_variable(var,
|
||||
*cpp_decltype_type::build(
|
||||
cpp_literal_expression::build(cpp_builtin_type::build("int"), "0")),
|
||||
nullptr, cpp_storage_class_none, false, false);
|
||||
else if (var.name() == "p")
|
||||
check_variable(var,
|
||||
*cpp_reference_type::
|
||||
build(cpp_cv_qualified_type::
|
||||
build(cpp_decltype_type::build(
|
||||
cpp_unexposed_expression::
|
||||
build(cpp_builtin_type::build("int"), "o")),
|
||||
cpp_cv_const),
|
||||
cpp_ref_lvalue),
|
||||
type_safe::ref(
|
||||
*cpp_unexposed_expression::build(cpp_builtin_type::build("int"),
|
||||
"o")),
|
||||
cpp_storage_class_none, false, false);
|
||||
else
|
||||
REQUIRE(false);
|
||||
});
|
||||
REQUIRE(count == 14u);
|
||||
REQUIRE(count == 16u);
|
||||
}
|
||||
|
||||
TEST_CASE("static cpp_variable")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue