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
14namespace Cody {
15
16#if NMS_CHECKING
17void (AssertFailed) (Location loc) noexcept
18{
19 (HCF) (msg: "assertion failed", loc);
20}
21void (Unreachable) (Location loc) noexcept
22{
23 (HCF) (msg: "unreachable reached", loc);
24}
25#endif
26
27void (HCF) (char const *msg
28#if NMS_CHECKING
29 , Location const loc
30#endif
31 ) noexcept
32{ // HCF - you goofed!
33
34#if !NMS_CHECKING
35 constexpr Location loc (nullptr, 0);
36#endif
37
38 fprintf (stderr, format: "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 (s: src);
46
47 if (!strncmp (s1: src, s2: file, n: l) && file[l] == '/')
48 file += l + 1;
49 }
50 fprintf (stderr, format: " at %s:%u", file, loc.Line ());
51 }
52 fprintf (stderr, format: "\n");
53 raise (SIGABRT);
54 exit (status: 2);
55}
56
57}
58

source code of libcody/fatal.cc