Update clang-format

This commit is contained in:
Jonathan Müller 2018-09-20 19:57:03 +02:00
commit 9f18b7f4d8
89 changed files with 11377 additions and 11546 deletions

View file

@ -46,81 +46,84 @@ alignas(type) int var;
auto file = parse({}, "cpp_attribute.cpp", code);
auto check_attribute = [](const cpp_attribute& attr, const char* name,
type_safe::optional<std::string> scope, bool variadic,
const char* args, cpp_attribute_kind kind) {
REQUIRE(attr.kind() == kind);
REQUIRE(attr.name() == name);
REQUIRE(attr.scope() == scope);
REQUIRE(attr.is_variadic() == variadic);
auto check_attribute
= [](const cpp_attribute& attr, const char* name, type_safe::optional<std::string> scope,
bool variadic, const char* args, cpp_attribute_kind kind) {
REQUIRE(attr.kind() == kind);
REQUIRE(attr.name() == name);
REQUIRE(attr.scope() == scope);
REQUIRE(attr.is_variadic() == variadic);
if (attr.arguments())
REQUIRE(attr.arguments().value().as_string() == args);
else
REQUIRE(*args == '\0');
};
if (attr.arguments())
REQUIRE(attr.arguments().value().as_string() == args);
else
REQUIRE(*args == '\0');
};
auto count =
test_visit<cpp_function>(*file,
[&](const cpp_entity& e) {
auto& attributes = e.attributes();
REQUIRE(attributes.size() >= 1u);
auto& attr = attributes.front();
auto count
= test_visit<cpp_function>(*file,
[&](const cpp_entity& e) {
auto& attributes = e.attributes();
REQUIRE(attributes.size() >= 1u);
auto& attr = attributes.front();
if (e.name() == "a" || e.name() == "b")
{
REQUIRE(attributes.size() == 2u);
REQUIRE(has_attribute(e, "attribute1"));
REQUIRE(has_attribute(e, "attribute2"));
check_attribute(attr, "attribute1", type_safe::nullopt,
false, "", cpp_attribute_kind::unknown);
check_attribute(attributes[1u], "attribute2",
type_safe::nullopt, false, "",
cpp_attribute_kind::unknown);
}
else if (e.name() == "c")
check_attribute(attr, "variadic", type_safe::nullopt, true,
"", cpp_attribute_kind::unknown);
else if (e.name() == "d")
{
REQUIRE(has_attribute(e, "ns::attribute"));
check_attribute(attr, "attribute", "ns", false, "",
cpp_attribute_kind::unknown);
}
else if (e.name() == "e")
check_attribute(attr, "attribute", type_safe::nullopt,
false, R"(arg1,arg2,+(){},42,"Hello!")",
cpp_attribute_kind::unknown);
else if (e.name() == "f")
{
REQUIRE(attributes.size() == 2u);
check_attribute(attr, "attribute", "ns", false, "+,-,0 4",
cpp_attribute_kind::unknown);
check_attribute(attributes[1u], "other_attribute",
type_safe::nullopt, false, "",
cpp_attribute_kind::unknown);
}
else if (e.name() == "g")
{
REQUIRE(has_attribute(e, cpp_attribute_kind::deprecated));
check_attribute(attr, "deprecated", type_safe::nullopt,
false, "", cpp_attribute_kind::deprecated);
}
else if (e.name() == "h")
check_attribute(attr, "maybe_unused", type_safe::nullopt,
false, "",
cpp_attribute_kind::maybe_unused);
else if (e.name() == "i")
check_attribute(attr, "nodiscard", type_safe::nullopt,
false, "", cpp_attribute_kind::nodiscard);
else if (e.name() == "j")
check_attribute(attr, "noreturn", type_safe::nullopt,
false, "", cpp_attribute_kind::noreturn);
else if (e.name() == "k")
check_attribute(attr, "const", type_safe::nullopt, false,
"", cpp_attribute_kind::unknown);
},
false);
if (e.name() == "a" || e.name() == "b")
{
REQUIRE(attributes.size() == 2u);
REQUIRE(has_attribute(e, "attribute1"));
REQUIRE(has_attribute(e, "attribute2"));
check_attribute(attr, "attribute1", type_safe::nullopt,
false, "", cpp_attribute_kind::unknown);
check_attribute(attributes[1u], "attribute2",
type_safe::nullopt, false, "",
cpp_attribute_kind::unknown);
}
else if (e.name() == "c")
check_attribute(attr, "variadic", type_safe::nullopt,
true, "", cpp_attribute_kind::unknown);
else if (e.name() == "d")
{
REQUIRE(has_attribute(e, "ns::attribute"));
check_attribute(attr, "attribute", "ns", false, "",
cpp_attribute_kind::unknown);
}
else if (e.name() == "e")
check_attribute(attr, "attribute", type_safe::nullopt,
false, R"(arg1,arg2,+(){},42,"Hello!")",
cpp_attribute_kind::unknown);
else if (e.name() == "f")
{
REQUIRE(attributes.size() == 2u);
check_attribute(attr, "attribute", "ns", false,
"+,-,0 4", cpp_attribute_kind::unknown);
check_attribute(attributes[1u], "other_attribute",
type_safe::nullopt, false, "",
cpp_attribute_kind::unknown);
}
else if (e.name() == "g")
{
REQUIRE(
has_attribute(e, cpp_attribute_kind::deprecated));
check_attribute(attr, "deprecated", type_safe::nullopt,
false, "",
cpp_attribute_kind::deprecated);
}
else if (e.name() == "h")
check_attribute(attr, "maybe_unused", type_safe::nullopt,
false, "",
cpp_attribute_kind::maybe_unused);
else if (e.name() == "i")
check_attribute(attr, "nodiscard", type_safe::nullopt,
false, "",
cpp_attribute_kind::nodiscard);
else if (e.name() == "j")
check_attribute(attr, "noreturn", type_safe::nullopt,
false, "", cpp_attribute_kind::noreturn);
else if (e.name() == "k")
check_attribute(attr, "const", type_safe::nullopt, false,
"", cpp_attribute_kind::unknown);
},
false);
REQUIRE(count == 10);
count = test_visit<cpp_class>(*file,

View file

@ -226,8 +226,8 @@ int d() {}
}
else if (entity.value().kind() == cpp_entity_kind::function_template_specialization_t)
{
auto& func =
static_cast<const cpp_function_template_specialization&>(entity.value());
auto& func
= static_cast<const cpp_function_template_specialization&>(entity.value());
if (func.name() == "templ_c")
{
REQUIRE(func.function().is_declaration());

View file

@ -270,15 +270,15 @@ using ns1::d;
)";
cpp_entity_index idx;
auto check_declaration = [&](const cpp_using_declaration& decl, const char* target_full_name,
unsigned no) {
auto target = decl.target();
REQUIRE((target.no_overloaded() == no));
for (auto entity : target.get(idx))
{
REQUIRE(full_name(*entity) == target_full_name);
}
};
auto check_declaration
= [&](const cpp_using_declaration& decl, const char* target_full_name, unsigned no) {
auto target = decl.target();
REQUIRE((target.no_overloaded() == no));
for (auto entity : target.get(idx))
{
REQUIRE(full_name(*entity) == target_full_name);
}
};
auto file = parse(idx, "cpp_using_declaration.cpp", code);
auto count = test_visit<cpp_using_declaration>(*file, [&](const cpp_using_declaration& decl) {

View file

@ -34,36 +34,36 @@ namespace ns2
)";
const char* order[] = {"A", "B", "ns", "C", "D", "E", "ns2", "F"};
auto check_macro = [](const cpp_macro_definition& macro, const char* replacement,
const char* args) {
REQUIRE(macro.replacement() == replacement);
if (args)
{
REQUIRE(macro.is_function_like());
auto check_macro
= [](const cpp_macro_definition& macro, const char* replacement, const char* args) {
REQUIRE(macro.replacement() == replacement);
if (args)
{
REQUIRE(macro.is_function_like());
std::string params;
for (auto& param : macro.parameters())
{
if (!params.empty())
params += ",";
params += param.name();
}
if (macro.is_variadic())
{
if (!params.empty())
params += ",";
params += "...";
}
std::string params;
for (auto& param : macro.parameters())
{
if (!params.empty())
params += ",";
params += param.name();
}
if (macro.is_variadic())
{
if (!params.empty())
params += ",";
params += "...";
}
REQUIRE(params == args);
}
else
{
REQUIRE(!macro.is_function_like());
REQUIRE(!macro.is_variadic());
REQUIRE(macro.parameters().empty());
}
};
REQUIRE(params == args);
}
else
{
REQUIRE(!macro.is_function_like());
REQUIRE(!macro.is_variadic());
REQUIRE(macro.parameters().empty());
}
};
auto file = parse({}, "cpp_macro_definition.cpp", code);
auto count = test_visit<cpp_macro_definition>(*file, [&](const cpp_macro_definition& macro) {
@ -117,25 +117,25 @@ b
auto file_a = parse(idx, "header_a.hpp", header_a);
auto file_b = parse(idx, "header_b.hpp", header_b);
auto count =
test_visit<cpp_include_directive>(*file_a, [&](const cpp_include_directive& include) {
if (include.name() == "iostream")
{
REQUIRE(include.target().name() == include.name());
REQUIRE(include.include_kind() == cppast::cpp_include_kind::system);
REQUIRE(include.target().get(idx).empty());
REQUIRE_THAT(include.full_path(), Catch::EndsWith("iostream"));
}
else if (include.name() == "cpp_include_directive-header.hpp")
{
REQUIRE(include.target().name() == include.name());
REQUIRE(include.include_kind() == cppast::cpp_include_kind::local);
REQUIRE(include.target().get(idx).empty());
REQUIRE(include.full_path() == "./cpp_include_directive-header.hpp");
}
else
REQUIRE(false);
});
auto count
= test_visit<cpp_include_directive>(*file_a, [&](const cpp_include_directive& include) {
if (include.name() == "iostream")
{
REQUIRE(include.target().name() == include.name());
REQUIRE(include.include_kind() == cppast::cpp_include_kind::system);
REQUIRE(include.target().get(idx).empty());
REQUIRE_THAT(include.full_path(), Catch::EndsWith("iostream"));
}
else if (include.name() == "cpp_include_directive-header.hpp")
{
REQUIRE(include.target().name() == include.name());
REQUIRE(include.include_kind() == cppast::cpp_include_kind::local);
REQUIRE(include.target().get(idx).empty());
REQUIRE(include.full_path() == "./cpp_include_directive-header.hpp");
}
else
REQUIRE(false);
});
REQUIRE(count == 2u);
count = test_visit<cpp_include_directive>(*file_b, [&](const cpp_include_directive& include) {

View file

@ -45,8 +45,8 @@ using e = void;
{
REQUIRE(p.kind() == cpp_entity_kind::template_type_parameter_t);
auto& param =
static_cast<const cpp_template_type_parameter&>(p);
auto& param
= static_cast<const cpp_template_type_parameter&>(p);
if (param.name() == "A")
{
REQUIRE(alias.name() == "a");
@ -132,8 +132,8 @@ using d = void;
REQUIRE(p.kind()
== cpp_entity_kind::non_type_template_parameter_t);
auto& param =
static_cast<const cpp_non_type_template_parameter&>(p);
auto& param
= static_cast<const cpp_non_type_template_parameter&>(p);
if (param.name() == "A")
{
REQUIRE(alias.name() == "a");
@ -227,8 +227,8 @@ using d = void;
REQUIRE(p.kind()
== cpp_entity_kind::template_template_parameter_t);
auto& param =
static_cast<const cpp_template_template_parameter&>(p);
auto& param
= static_cast<const cpp_template_template_parameter&>(p);
REQUIRE(param.keyword() == cpp_template_keyword::keyword_class);
if (param.name() == "A")
{

View file

@ -134,8 +134,8 @@ bool equal_types(const cpp_entity_index& idx, const cpp_type& parsed, const cpp_
case cpp_type_kind::template_parameter_t:
{
auto& entity_parsed = static_cast<const cpp_template_parameter_type&>(parsed).entity();
auto& entity_synthesized =
static_cast<const cpp_template_parameter_type&>(synthesized).entity();
auto& entity_synthesized
= static_cast<const cpp_template_parameter_type&>(synthesized).entity();
return equal_ref(idx, entity_parsed, entity_synthesized);
}
case cpp_type_kind::template_instantiation_t:
@ -357,8 +357,8 @@ typedef decltype(0) w;
}
else if (alias.name() == "d")
{
auto type =
cpp_pointer_type::build(add_cv(cpp_builtin_type::build(cpp_uint), cpp_cv_const));
auto type
= cpp_pointer_type::build(add_cv(cpp_builtin_type::build(cpp_uint), cpp_cv_const));
REQUIRE(equal_types(idx, alias.underlying_type(), *type));
}
else if (alias.name() == "e")
@ -375,9 +375,9 @@ typedef decltype(0) w;
}
else if (alias.name() == "g")
{
auto type =
cpp_reference_type::build(add_cv(cpp_builtin_type::build(cpp_int), cpp_cv_const),
cpp_ref_rvalue);
auto type
= cpp_reference_type::build(add_cv(cpp_builtin_type::build(cpp_int), cpp_cv_const),
cpp_ref_rvalue);
REQUIRE(equal_types(idx, alias.underlying_type(), *type));
}
else if (alias.name() == "h")
@ -399,21 +399,21 @@ typedef decltype(0) w;
}
else if (alias.name() == "k")
{
auto type =
cpp_array_type::build(cpp_builtin_type::build(cpp_int), make_size("42", true));
auto type
= cpp_array_type::build(cpp_builtin_type::build(cpp_int), make_size("42", true));
REQUIRE(equal_types(idx, alias.underlying_type(), *type));
}
else if (alias.name() == "l")
{
auto type =
cpp_array_type::build(cpp_pointer_type::build(cpp_builtin_type::build(cpp_float)),
nullptr);
auto type
= cpp_array_type::build(cpp_pointer_type::build(cpp_builtin_type::build(cpp_float)),
nullptr);
REQUIRE(equal_types(idx, alias.underlying_type(), *type));
}
else if (alias.name() == "m")
{
auto type =
cpp_array_type::build(cpp_builtin_type::build(cpp_char), make_size("42", true));
auto type
= cpp_array_type::build(cpp_builtin_type::build(cpp_char), make_size("42", true));
REQUIRE(equal_types(idx, alias.underlying_type(), *type));
}
else if (alias.name() == "n")
@ -474,10 +474,12 @@ typedef decltype(0) w;
}
else if (alias.name() == "s")
{
auto pointee = cpp_member_object_type::
build(cpp_user_defined_type::build(cpp_type_ref(cpp_entity_id(""), "foo")),
cpp_unexposed_type::build(
"int")); // type not exposed directly for some reason
auto pointee
= cpp_member_object_type::build(cpp_user_defined_type::build(
cpp_type_ref(cpp_entity_id(""), "foo")),
cpp_unexposed_type::build(
"int")); // type not exposed directly for some
// reason
auto type = cpp_pointer_type::build(std::move(pointee));
REQUIRE(equal_types(idx, alias.underlying_type(), *type));

View file

@ -16,53 +16,53 @@ TEST_CASE("stdlib", "[!hide][integration]")
//#include <cstdlib> -- problem with compiler built-in stuff on OSX
#include <csignal>
//#include <csetjmp> -- same as above
#include <cstdarg>
#include <typeinfo>
#include <typeindex>
#include <type_traits>
#include <bitset>
#include <functional>
#include <utility>
#include <ctime>
#include <chrono>
#include <cstdarg>
#include <cstddef>
#include <ctime>
#include <functional>
#include <initializer_list>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <utility>
#include <new>
#include <memory>
#include <new>
#include <scoped_allocator>
#include <climits>
#include <cfloat>
#include <climits>
#include <cstdint>
//#include <cinttypes> -- missing types from C header (for some reason)
#include <limits>
//#include <exception> -- weird issue with compiler built-in stuff
#include <stdexcept>
#include <cassert>
#include <system_error>
#include <cerrno>
#include <stdexcept>
#include <system_error>
#include <cctype>
#include <cwctype>
#include <cstring>
#include <cwchar>
#include <cwctype>
//#include <cuchar> -- not supported on CI
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <list>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
@ -70,22 +70,22 @@ TEST_CASE("stdlib", "[!hide][integration]")
//#include <cmath> -- non-conforming GCC extension with regards to constexpr
//#include <complex> -- weird double include issue under MSVC
#include <valarray>
#include <random>
#include <numeric>
#include <random>
#include <ratio>
#include <valarray>
//#include <cfenv> -- same issue with cinttypes
#include <iosfwd>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <streambuf>
#include <cstdio>
#include <locale>
//#include <clocale> -- issue on OSX
@ -94,10 +94,10 @@ TEST_CASE("stdlib", "[!hide][integration]")
//#include <atomic> -- issue on MSVC
#include <thread>
#include <mutex>
#include <future>
#include <condition_variable>
#include <future>
#include <mutex>
#include <thread>
)";
write_file("stdlib.cpp", code);

View file

@ -57,7 +57,7 @@ TEST_CASE("libclang_compile_config")
}
])";
#define CPPAST_DETAIL_DRIVE "C:"
# define CPPAST_DETAIL_DRIVE "C:"
#else
auto json = R"([
@ -83,7 +83,7 @@ TEST_CASE("libclang_compile_config")
}
])";
#define CPPAST_DETAIL_DRIVE
# define CPPAST_DETAIL_DRIVE
#endif

View file

@ -65,7 +65,8 @@ TEST_CASE("preprocessing use external macro")
auto result = NAN;
#endif
)", fast_preprocessing);
)",
fast_preprocessing);
test_visit<cpp_variable>(*file, [&](const cpp_variable&) {});
}
@ -302,7 +303,8 @@ void j();
{
if (comment.content == "cstddef\ncstddef")
// happens if include parsing is not supported
// error is still going to be detected because if it is supported, the entity will be matched above
// error is still going to be detected because if it is supported, the entity will be
// matched above
add = 1u;
else
REQUIRE(comment.content == "u");