Nathan Sidwell | 3623032 | 2020-12-14 08:10:27 -0800 | [diff] [blame] | 1 | // CODYlib -*- mode:c++ -*- |
| 2 | // Copyright (C) 2019-2020 Nathan Sidwell, nathan@acm.org |
| 3 | // License: Apache v2.0 |
| 4 | |
| 5 | // Cody |
| 6 | #include "internal.hh" |
| 7 | // C |
| 8 | #include <csignal> |
| 9 | #include <cstdint> |
| 10 | #include <cstdio> |
| 11 | #include <cstdlib> |
| 12 | #include <cstring> |
| 13 | |
| 14 | namespace Cody { |
| 15 | |
| 16 | #if NMS_CHECKING |
| 17 | void (AssertFailed) (Location loc) noexcept |
| 18 | { |
| 19 | (HCF) ("assertion failed", loc); |
| 20 | } |
| 21 | void (Unreachable) (Location loc) noexcept |
| 22 | { |
| 23 | (HCF) ("unreachable reached", loc); |
| 24 | } |
| 25 | #endif |
| 26 | |
| 27 | void (HCF) (char const *msg |
| 28 | #if NMS_CHECKING |
| 29 | , Location const loc |
| 30 | #endif |
| 31 | ) noexcept |
| 32 | { // HCF - you goofed! |
Nathan Sidwell | 3623032 | 2020-12-14 08:10:27 -0800 | [diff] [blame] | 33 | |
| 34 | #if !NMS_CHECKING |
| 35 | constexpr Location loc (nullptr, 0); |
| 36 | #endif |
| 37 | |
| 38 | fprintf (stderr, "CODYlib: %s", msg ? msg : "internal error"); |
| 39 | if (char const *file = loc.File ()) |
| 40 | { |
| 41 | char const *src = SRCDIR; |
| 42 | |
| 43 | if (src[0]) |
| 44 | { |
| 45 | size_t l = strlen (src); |
| 46 | |
| 47 | if (!strncmp (src, file, l) && file[l] == '/') |
| 48 | file += l + 1; |
| 49 | } |
| 50 | fprintf (stderr, " at %s:%u", file, loc.Line ()); |
| 51 | } |
| 52 | fprintf (stderr, "\n"); |
| 53 | raise (SIGABRT); |
| 54 | exit (2); |
| 55 | } |
| 56 | |
Nathan Sidwell | 3623032 | 2020-12-14 08:10:27 -0800 | [diff] [blame] | 57 | } |