Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pre-commit formatting of C++ files #1536

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ repos:
pass_filenames: false
stages: ["commit"]

- id: stray_baselines
- id: stray-baselines
name: Check for stray BTest baselines
entry: ./tests/Scripts/stray_baselines.py
additional_dependencies:
- btest
language: python
pass_filenames: false
stages: ["commit"]
Expand All @@ -38,7 +40,7 @@ repos:
rev: 'v16.0.3'
hooks:
- id: clang-format
types: ["c", "c++"]
types_or: ["c", "c++"]
stages: ["commit"]

- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
16 changes: 8 additions & 8 deletions hilti/runtime/src/fiber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ static const std::string debug_stream_fibers = "fibers";
// Wrapper similar to HILTI_RT_DEBUG that adds the current fiber to the message.
#define HILTI_RT_FIBER_DEBUG(tag, msg) \
{ \
if ( ::hilti::rt::detail::unsafeGlobalState()->debug_logger && \
::hilti::rt::detail::unsafeGlobalState()->debug_logger->isEnabled(debug_stream_fibers) ) \
if ( ::hilti::rt::detail::unsafeGlobalState()->debug_logger && \
::hilti::rt::detail::unsafeGlobalState()->debug_logger->isEnabled(debug_stream_fibers) ) \
::hilti::rt::debug::detail::print(debug_stream_fibers, \
fmt("[%s/%s] %s", *context::detail::get()->fiber.current, tag, msg)); \
}

#define HILTI_RT_FIBER_DEBUG_NO_CONTEXT(tag, msg) \
{ \
if ( ::hilti::rt::detail::unsafeGlobalState()->debug_logger && \
::hilti::rt::detail::unsafeGlobalState()->debug_logger->isEnabled(debug_stream_fibers) ) \
if ( ::hilti::rt::detail::unsafeGlobalState()->debug_logger && \
::hilti::rt::detail::unsafeGlobalState()->debug_logger->isEnabled(debug_stream_fibers) ) \
::hilti::rt::debug::detail::print(debug_stream_fibers, fmt("[none/%s] %s", tag, msg)); \
}

Expand Down Expand Up @@ -173,8 +173,8 @@ detail::Fiber::Fiber(Type type) : _type(type), _fiber(std::make_unique<::Fiber>(
}

case Type::SwitchTrampoline:
if ( ! ::fiber_alloc(_fiber.get(), configuration::detail::unsafeGet().fiber_individual_stack_size, fiber_bottom_abort,
this, FiberGuardFlags) )
if ( ! ::fiber_alloc(_fiber.get(), configuration::detail::unsafeGet().fiber_individual_stack_size,
fiber_bottom_abort, this, FiberGuardFlags) )
internalError("could not allocate individual-stack fiber");

#ifdef HILTI_HAVE_ASAN
Expand All @@ -195,8 +195,8 @@ detail::Fiber::Fiber(Type type) : _type(type), _fiber(std::make_unique<::Fiber>(
}

case Type::IndividualStack: {
if ( ! ::fiber_alloc(_fiber.get(), configuration::detail::unsafeGet().fiber_individual_stack_size, fiber_bottom_abort,
this, FiberGuardFlags) )
if ( ! ::fiber_alloc(_fiber.get(), configuration::detail::unsafeGet().fiber_individual_stack_size,
fiber_bottom_abort, this, FiberGuardFlags) )
internalError("could not allocate individual-stack fiber");

#ifdef HILTI_HAVE_ASAN
Expand Down
3 changes: 1 addition & 2 deletions hilti/runtime/src/library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
using namespace hilti::rt;

std::string hilti::rt::library::Version::toJSON() const {
auto version =
nlohmann::json{{"magic", magic}, {"hilti_version", hilti_version}, {"debug", debug}};
auto version = nlohmann::json{{"magic", magic}, {"hilti_version", hilti_version}, {"debug", debug}};
std::stringstream json;
json << version;
return json.str();
Expand Down
3 changes: 2 additions & 1 deletion hilti/runtime/src/tests/address.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ TEST_CASE("constructs from an `::in_addr4`") { CHECK_EQ(std::string(Address(*mak

TEST_CASE("constructs from an `::in6_addr`") {
std::string addr = std::string(Address(*make_in6_addr("::4996:2d2:0:0:4996:2d2")));
auto is_correct = (addr == "::4996:2d2:0:0:4996:2d2" || addr == "0:0:4996:2d2::4996:2d2"); // Alpine has been seen to return the latter
auto is_correct = (addr == "::4996:2d2:0:0:4996:2d2" ||
addr == "0:0:4996:2d2::4996:2d2"); // Alpine has been seen to return the latter

CHECK(is_correct);
}
Expand Down
2 changes: 1 addition & 1 deletion hilti/runtime/src/tests/fiber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <hilti/rt/configuration.h>
#include <hilti/rt/doctest.h>
#include <hilti/rt/exception.h>
#include <hilti/rt/fiber.h>
#include <hilti/rt/fiber-check-stack.h>
#include <hilti/rt/fiber.h>
#include <hilti/rt/init.h>
#include <hilti/rt/result.h>

Expand Down
20 changes: 12 additions & 8 deletions hilti/runtime/src/tests/integer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ TEST_CASE("pack") {
CHECK_EQ(integer::pack<uint16_t>(256, ByteOrder::Big), "\x01\x00"_b);
CHECK_EQ(integer::pack<uint16_t>(256, ByteOrder::Little), "\x00\x01"_b);
CHECK_EQ(integer::pack<uint16_t>(1, ByteOrder::Big), "\x00\x01"_b);
CHECK_THROWS_WITH_AS(integer::pack<uint16_t>(1, ByteOrder::Undef), "attempt to pack value with undefined byte order", const RuntimeError&);
CHECK_THROWS_WITH_AS(integer::pack<uint16_t>(1, ByteOrder::Undef),
"attempt to pack value with undefined byte order", const RuntimeError&);

CHECK_EQ(integer::pack<uint32_t>(0x01020304, ByteOrder::Big), "\x01\x02\x03\x04"_b);
CHECK_EQ(integer::pack<uint32_t>(0x01020304, ByteOrder::Little), "\x04\x03\x02\x01"_b);
CHECK_EQ(integer::pack<uint64_t>(0x0102030405060708, ByteOrder::Big), "\x01\x02\x03\x04\x05\x06\x07\x08"_b);
CHECK_EQ(integer::pack<uint64_t>(0x0102030405060708, ByteOrder::Little), "\x08\x07\x06\x05\x04\x03\x02\x01"_b);

}

TEST_CASE("unpack") {
Expand All @@ -199,18 +199,22 @@ TEST_CASE("unpack") {
Result16(result::Error("insufficient data to unpack integer")));
CHECK_EQ(integer::unpack<uint16_t>("\x01"_b, ByteOrder::Little),
Result16(result::Error("insufficient data to unpack integer")));
CHECK_EQ(integer::unpack<uint16_t>("\x00\x01"_b, ByteOrder::Undef), Result16(result::Error("undefined byte order")));
CHECK_EQ(integer::unpack<uint16_t>("\x00\x01"_b, ByteOrder::Undef),
Result16(result::Error("undefined byte order")));

CHECK_EQ(integer::unpack<uint16_t>("\x01\x00"_b, ByteOrder::Little), Result16(std::make_tuple(1, ""_b)));
CHECK_EQ(integer::unpack<uint16_t>("\x01\x00"_b, ByteOrder::Big), Result16(std::make_tuple(256, ""_b)));
CHECK_EQ(integer::unpack<uint16_t>("\x00\x01"_b, ByteOrder::Little), Result16(std::make_tuple(256, ""_b)));
CHECK_EQ(integer::unpack<uint16_t>("\x00\x01"_b, ByteOrder::Big), Result16(std::make_tuple(1, ""_b)));

CHECK_EQ(integer::unpack<uint32_t>("\x01\x02\x03\x04"_b, ByteOrder::Big), Result32(std::make_tuple(0x01020304, ""_b)));
CHECK_EQ(integer::unpack<uint32_t>("\x04\x03\x02\x01"_b, ByteOrder::Little), Result32(std::make_tuple(0x01020304, ""_b)));
CHECK_EQ(integer::unpack<uint64_t>("\x01\x02\x03\x04\x05\x06\x07\x08"_b, ByteOrder::Big), Result64(std::make_tuple(0x0102030405060708, ""_b)));
CHECK_EQ(integer::unpack<uint64_t>("\x08\x07\x06\x05\x04\x03\x02\x01"_b, ByteOrder::Little), Result64(std::make_tuple(0x0102030405060708, ""_b)));

CHECK_EQ(integer::unpack<uint32_t>("\x01\x02\x03\x04"_b, ByteOrder::Big),
Result32(std::make_tuple(0x01020304, ""_b)));
CHECK_EQ(integer::unpack<uint32_t>("\x04\x03\x02\x01"_b, ByteOrder::Little),
Result32(std::make_tuple(0x01020304, ""_b)));
CHECK_EQ(integer::unpack<uint64_t>("\x01\x02\x03\x04\x05\x06\x07\x08"_b, ByteOrder::Big),
Result64(std::make_tuple(0x0102030405060708, ""_b)));
CHECK_EQ(integer::unpack<uint64_t>("\x08\x07\x06\x05\x04\x03\x02\x01"_b, ByteOrder::Little),
Result64(std::make_tuple(0x0102030405060708, ""_b)));
}

TEST_SUITE_END();
45 changes: 36 additions & 9 deletions hilti/runtime/src/tests/string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,54 @@ TEST_CASE("lower") {
CHECK_EQ(string::lower(""), "");
CHECK_EQ(string::lower("123Abc"), "123abc");
CHECK_EQ(string::lower("GÄNSEFÜẞCHEN"), "gänsefüßchen");
CHECK_EQ(string::lower("\xc3\x28" "aBcD", string::DecodeErrorStrategy::REPLACE), "\ufffd(abcd");
CHECK_EQ(string::lower("\xc3\x28" "aBcD", string::DecodeErrorStrategy::IGNORE), "(abcd");
CHECK_THROWS_WITH_AS(string::lower("\xc3\x28" "aBcD", string::DecodeErrorStrategy::STRICT), "illegal UTF8 sequence in string", const RuntimeError&);
CHECK_EQ(string::lower("\xc3\x28"
"aBcD",
string::DecodeErrorStrategy::REPLACE),
"\ufffd(abcd");
CHECK_EQ(string::lower("\xc3\x28"
"aBcD",
string::DecodeErrorStrategy::IGNORE),
"(abcd");
CHECK_THROWS_WITH_AS(string::lower("\xc3\x28"
"aBcD",
string::DecodeErrorStrategy::STRICT),
"illegal UTF8 sequence in string", const RuntimeError&);
}

TEST_CASE("size") {
CHECK_EQ(string::size(""), 0U);
CHECK_EQ(string::size("123Abc"), 6U);
CHECK_EQ(string::size("Gänsefüßchen"), 12U);
CHECK_EQ(string::size("\xc3\x28" "aBcD", string::DecodeErrorStrategy::REPLACE), 6U);
CHECK_EQ(string::size("\xc3\x28" "aBcD", string::DecodeErrorStrategy::IGNORE), 5U);
CHECK_THROWS_WITH_AS(string::size("\xc3\x28" "aBcD", string::DecodeErrorStrategy::STRICT), "illegal UTF8 sequence in string", const RuntimeError&);
CHECK_EQ(string::size("\xc3\x28"
"aBcD",
string::DecodeErrorStrategy::REPLACE),
6U);
CHECK_EQ(string::size("\xc3\x28"
"aBcD",
string::DecodeErrorStrategy::IGNORE),
5U);
CHECK_THROWS_WITH_AS(string::size("\xc3\x28"
"aBcD",
string::DecodeErrorStrategy::STRICT),
"illegal UTF8 sequence in string", const RuntimeError&);
}

TEST_CASE("upper") {
CHECK_EQ(string::upper(""), "");
CHECK_EQ(string::upper("123Abc"), "123ABC");
CHECK_EQ(string::upper("Gänsefüßchen"), "GÄNSEFÜẞCHEN");
CHECK_EQ(string::upper("\xc3\x28" "aBcD", string::DecodeErrorStrategy::REPLACE), "\ufffd(ABCD");
CHECK_EQ(string::upper("\xc3\x28" "aBcD", string::DecodeErrorStrategy::IGNORE), "(ABCD");
CHECK_THROWS_WITH_AS(string::upper("\xc3\x28" "aBcD", string::DecodeErrorStrategy::STRICT), "illegal UTF8 sequence in string", const RuntimeError&);
CHECK_EQ(string::upper("\xc3\x28"
"aBcD",
string::DecodeErrorStrategy::REPLACE),
"\ufffd(ABCD");
CHECK_EQ(string::upper("\xc3\x28"
"aBcD",
string::DecodeErrorStrategy::IGNORE),
"(ABCD");
CHECK_THROWS_WITH_AS(string::upper("\xc3\x28"
"aBcD",
string::DecodeErrorStrategy::STRICT),
"illegal UTF8 sequence in string", const RuntimeError&);
}

TEST_SUITE_END();
2 changes: 1 addition & 1 deletion hilti/runtime/src/tests/struct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#include <hilti/rt/doctest.h>
#include <hilti/rt/extension-points.h>
#include <hilti/rt/logging.h>
#include <hilti/rt/types/integer.h>
#include <hilti/rt/types/struct.h>
#include <hilti/rt/logging.h>

using namespace hilti::rt;

Expand Down
7 changes: 4 additions & 3 deletions hilti/runtime/src/tests/type-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const hilti::rt::TypeInfo __ti_Test_Y =
{"Test::Y", "Test::Y",
new hilti::rt::type_info::Struct(std::vector<hilti::rt::type_info::struct_::Field>(
{hilti::rt::type_info::struct_::Field{"b", &hilti::rt::type_info::bool_, offsetof(Test::Y, b), false, false},
hilti::rt::type_info::struct_::Field{"r", &hilti::rt::type_info::real, offsetof(Test::Y, r), false, false}}))};
hilti::rt::type_info::struct_::Field{"r", &hilti::rt::type_info::real, offsetof(Test::Y, r), false,
false}}))};
} // namespace
} // namespace __hlt::type_info

Expand Down Expand Up @@ -128,8 +129,8 @@ TEST_CASE("internal fields") {
new type_info::Struct(
{type_info::struct_::Field{"f1", &type_info::int32, offsetof(A, f1), false, false},
type_info::struct_::Field{"f2", &type_info::string, offsetof(A, f2), false, false},
type_info::struct_::Field{"__internal", &type_info::bool_, offsetof(A, __internal),
true, false}})};
type_info::struct_::Field{"__internal", &type_info::bool_, offsetof(A, __internal), true,
false}})};

auto sx = StrongReference<A>({42, "foo", true});
auto p = type_info::value::Parent(sx);
Expand Down
3 changes: 2 additions & 1 deletion hilti/toolchain/src/compiler/codegen/ctors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ struct Visitor : hilti::visitor::PreOrder<cxx::Expression, Visitor> {
values.emplace_back("std::nullopt");
}

return fmt("hilti::rt::Bitfield<%s>{{}, std::make_tuple(%s)}", util::join(types, ", "), util::join(values, ", "));
return fmt("hilti::rt::Bitfield<%s>{{}, std::make_tuple(%s)}", util::join(types, ", "),
util::join(values, ", "));
}

result_t operator()(const ctor::Bool& n) { return fmt("::hilti::rt::Bool(%s)", n.value() ? "true" : "false"); }
Expand Down
15 changes: 8 additions & 7 deletions hilti/toolchain/src/compiler/codegen/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,9 @@ struct VisitorStorage : hilti::visitor::PreOrder<CxxTypes, VisitorStorage> {
result_t operator()(const type::Bool& n) { return CxxTypes{.base_type = "::hilti::rt::Bool"}; }

result_t operator()(const type::Bitfield& n) {
auto x = node::transform(n.bits(true),
[this](const auto& b) { return cg->compile(b.itemType(), codegen::TypeUsage::Storage); });
auto x = node::transform(n.bits(true), [this](const auto& b) {
return cg->compile(b.itemType(), codegen::TypeUsage::Storage);
});
auto t = fmt("hilti::rt::Bitfield<%s>", util::join(x, ", "));
return CxxTypes{.base_type = t};
}
Expand Down Expand Up @@ -818,9 +819,9 @@ struct VisitorTypeInfoDynamic : hilti::visitor::PreOrder<cxx::Expression, Visito
auto ttype = cg->compile(p.node.as<Type>(), codegen::TypeUsage::Storage);

for ( const auto&& [i, b] : util::enumerate(n.bits()) )
elems.push_back(
fmt("::hilti::rt::type_info::bitfield::Bits{ \"%s\", %s, hilti::rt::bitfield::elementOffset<%s, %d>() }",
b.id(), cg->typeInfo(b.itemType()), ttype, i));
elems.push_back(fmt(
"::hilti::rt::type_info::bitfield::Bits{ \"%s\", %s, hilti::rt::bitfield::elementOffset<%s, %d>() }",
b.id(), cg->typeInfo(b.itemType()), ttype, i));

return fmt("::hilti::rt::type_info::Bitfield(std::vector<::hilti::rt::type_info::bitfield::Bits>({%s}))",
util::join(elems, ", "));
Expand Down Expand Up @@ -902,8 +903,8 @@ struct VisitorTypeInfoDynamic : hilti::visitor::PreOrder<cxx::Expression, Visito
cxx_type_id = *x;

fields.push_back(fmt("::hilti::rt::type_info::struct_::Field{ \"%s\", %s, offsetof(%s, %s), %s, %s%s }",
cxx::ID(f.id()), cg->typeInfo(f.type()), cxx_type_id, cxx::ID(f.id()), f.isInternal(), f.isAnonymous(),
accessor));
cxx::ID(f.id()), cg->typeInfo(f.type()), cxx_type_id, cxx::ID(f.id()), f.isInternal(),
f.isAnonymous(), accessor));
}

return fmt("::hilti::rt::type_info::Struct(std::vector<::hilti::rt::type_info::struct_::Field>({%s}))",
Expand Down
6 changes: 4 additions & 2 deletions hilti/toolchain/src/compiler/cxx/linker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ void cxx::Linker::finalize() {

auto cxx_namespace = _codegen->context()->options().cxx_namespace_intern;

unit.add(fmt("const char HILTI_EXPORT HILTI_WEAK * %s_hlto_library_version = R\"(%s)\";", cxx_namespace, version.toJSON()));
unit.add(fmt("const char HILTI_EXPORT HILTI_WEAK * %s_hlto_bind_to_version = " HILTI_VERSION_FUNCTION_STRING "();", cxx_namespace));
unit.add(fmt("const char HILTI_EXPORT HILTI_WEAK * %s_hlto_library_version = R\"(%s)\";", cxx_namespace,
version.toJSON()));
unit.add(fmt("const char HILTI_EXPORT HILTI_WEAK * %s_hlto_bind_to_version = " HILTI_VERSION_FUNCTION_STRING "();",
cxx_namespace));

// Create a scope string that's likely to be unique to this linker module.
std::size_t hash = 0;
Expand Down
1 change: 0 additions & 1 deletion hilti/toolchain/tests/id-base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <hilti/base/id-base.h>



using namespace hilti;

std::string normalize_id(std::string id) { return id; }
Expand Down
10 changes: 5 additions & 5 deletions spicy/runtime/src/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void Driver::_debugStats(const hilti::rt::ValueReference<hilti::rt::Stream>& dat
auto max_stack_size = pretty_print_number(ru.max_fiber_stack_size);
auto cached_stacks = pretty_print_number(ru.cached_fibers);

DRIVER_DEBUG(fmt("memory: heap=%s fibers-cur=%s fibers-cached=%s fibers-max=%s fiber-stack-max=%s", memory_heap, num_stacks,
cached_stacks, max_stacks, max_stack_size));
DRIVER_DEBUG(fmt("memory: heap=%s fibers-cur=%s fibers-cached=%s fibers-max=%s fiber-stack-max=%s", memory_heap,
num_stacks, cached_stacks, max_stacks, max_stack_size));
}

void Driver::_debugStats(size_t current_flows, size_t current_connections) {
Expand All @@ -88,8 +88,8 @@ void Driver::_debugStats(size_t current_flows, size_t current_connections) {
auto max_stack_size = pretty_print_number(stats.max_fiber_stack_size);
auto cached_stacks = pretty_print_number(stats.cached_fibers);

DRIVER_DEBUG(fmt("memory : heap=%s fibers-cur=%s fibers-cached=%s fibers-max=%s fiber-stack-max=%s", memory_heap, num_stacks,
cached_stacks, max_stacks, max_stack_size));
DRIVER_DEBUG(fmt("memory : heap=%s fibers-cur=%s fibers-cached=%s fibers-max=%s fiber-stack-max=%s", memory_heap,
num_stacks, cached_stacks, max_stacks, max_stack_size));
}

Result<Nothing> Driver::listParsers(std::ostream& out) {
Expand Down Expand Up @@ -174,7 +174,7 @@ Result<spicy::rt::ParsedUnit> Driver::processInput(const spicy::rt::Parser& pars

in.read(buffer, static_cast<std::streamsize>(len));

{
{
auto profiler = hilti::rt::profiler::start(fmt("spicy/prepare/input/%s", parser.name));

if ( auto n = in.gcount() )
Expand Down
7 changes: 3 additions & 4 deletions spicy/toolchain/src/compiler/codegen/unit-builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Type CodeGen::compileUnit(const type::Unit& unit, bool declare_only) {

add_hook("0x25_init", {});
add_hook("0x25_done", {});
add_hook("0x25_error", { builder::parameter("__except", type::String()) });
add_hook("0x25_error", {builder::parameter("__except", type::String())});
add_hook("0x25_print", {});
add_hook("0x25_finally", {});

Expand Down Expand Up @@ -347,9 +347,8 @@ Type CodeGen::compileUnit(const type::Unit& unit, bool declare_only) {
_pb.builder()->addAssign(builder::id(ID(*unit.id(), "__parser")), parser);

_pb.builder()->addExpression(
builder::call("spicy_rt::registerParser",
{builder::id(ID(*unit.id(), "__parser")), builder::scope(),
builder::strong_reference(unit)}));
builder::call("spicy_rt::registerParser", {builder::id(ID(*unit.id(), "__parser")), builder::scope(),
builder::strong_reference(unit)}));
});

auto block = _pb.popBuilder()->block();
Expand Down
Loading