-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0df0e02
commit d921878
Showing
3 changed files
with
83 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// Copyright (c) 2023 Krystian Stasiowski ([email protected]) | ||
// | ||
// Official repository: https://github.com/cppalliance/mrdox | ||
// | ||
|
||
#ifndef MRDOX_API_SUPPORT_ASSERT_HPP | ||
#define MRDOX_API_SUPPORT_ASSERT_HPP | ||
|
||
#include <cstdint> | ||
|
||
namespace clang { | ||
namespace mrdox { | ||
|
||
#ifdef NDEBUG | ||
#ifdef __GNUC__ | ||
#define MRDOX_UNREACHABLE() static_cast<void>(__builtin_unreachable()) | ||
#elif defined(_MSC_VER) | ||
#define MRDOX_UNREACHABLE() static_cast<void>(__assume(false)) | ||
#endif | ||
#define MRDOX_ASSERT(x) static_cast<void>(false) | ||
#else | ||
#ifdef __GNUC__ | ||
#define MRDOX_UNREACHABLE() static_cast<void>(__builtin_trap(), __builtin_unreachable()) | ||
#elif defined(_MSC_VER) | ||
#define MRDOX_UNREACHABLE() static_cast<void>(__debugbreak(), __assume(false)) | ||
#endif | ||
|
||
void | ||
assert_failed( | ||
const char* msg, | ||
const char* file, | ||
std::uint_least32_t line); | ||
|
||
#define MRDOX_ASSERT(x) static_cast<void>(!! (x) || \ | ||
(assert_failed(#x, __builtin_FILE(), __builtin_LINE()), \ | ||
MRDOX_UNREACHABLE(), true)) | ||
#endif | ||
|
||
} // mrdox | ||
} // clang | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// Copyright (c) 2023 Krystian Stasiowski ([email protected]) | ||
// | ||
// Official repository: https://github.com/cppalliance/mrdox | ||
// | ||
|
||
#include <mrdox/Support/Assert.hpp> | ||
#include <mrdox/Support/Path.hpp> | ||
#include <fmt/format.h> | ||
#include <llvm/Support/raw_ostream.h> | ||
|
||
namespace SourceFileNames { | ||
extern char const* getFileName(char const*) noexcept; | ||
} // SourceFileNames | ||
|
||
namespace clang { | ||
namespace mrdox { | ||
|
||
void | ||
assert_failed( | ||
const char* msg, | ||
const char* file, | ||
std::uint_least32_t line) | ||
{ | ||
llvm::errs() << fmt::format( | ||
"assertion failed: {} on line {} in {}\n", | ||
msg, line, ::SourceFileNames::getFileName(file)); | ||
} | ||
|
||
} // mrdox | ||
} // clang |