fatal.cc 1022 B

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