| 1 |
|
| 2 |
/* Compiler implementation of the D programming language |
| 3 |
* Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved |
| 4 |
* written by Walter Bright |
| 5 |
* https://www.digitalmars.com |
| 6 |
* Distributed under the Boost Software License, Version 1.0. |
| 7 |
* https://www.boost.org/LICENSE_1_0.txt |
| 8 |
* https://github.com/dlang/dmd/blob/master/src/dmd/errors.h |
| 9 |
*/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include "root/dsystem.h" |
| 14 |
|
| 15 |
struct Loc; |
| 16 |
|
| 17 |
// Constants used to discriminate kinds of error messages. |
| 18 |
enum class ErrorKind |
| 19 |
{ |
| 20 |
warning = 0, |
| 21 |
deprecation = 1, |
| 22 |
error = 2, |
| 23 |
tip = 3, |
| 24 |
message = 4, |
| 25 |
}; |
| 26 |
|
| 27 |
#if defined(__GNUC__) |
| 28 |
#define D_ATTRIBUTE_FORMAT(m, n) __attribute__((format(printf, m, n))) __attribute__((nonnull (m))) |
| 29 |
#else |
| 30 |
#define D_ATTRIBUTE_FORMAT(m, n) |
| 31 |
#endif |
| 32 |
|
| 33 |
// Print a warning, deprecation, or error, accepts printf-like format specifiers. |
| 34 |
D_ATTRIBUTE_FORMAT(2, 3) void warning(Loc loc, const char *format, ...); |
| 35 |
D_ATTRIBUTE_FORMAT(2, 3) void warningSupplemental(Loc loc, const char *format, ...); |
| 36 |
D_ATTRIBUTE_FORMAT(2, 3) void deprecation(Loc loc, const char *format, ...); |
| 37 |
D_ATTRIBUTE_FORMAT(2, 3) void deprecationSupplemental(Loc loc, const char *format, ...); |
| 38 |
D_ATTRIBUTE_FORMAT(2, 3) void error(Loc loc, const char *format, ...); |
| 39 |
D_ATTRIBUTE_FORMAT(4, 5) void error(const char *filename, unsigned linnum, unsigned charnum, const char *format, ...); |
| 40 |
D_ATTRIBUTE_FORMAT(2, 3) void errorSupplemental(Loc loc, const char *format, ...); |
| 41 |
D_ATTRIBUTE_FORMAT(1, 2) void message(const char *format, ...); |
| 42 |
D_ATTRIBUTE_FORMAT(2, 3) void message(Loc loc, const char *format, ...); |
| 43 |
D_ATTRIBUTE_FORMAT(1, 2) void tip(const char *format, ...); |
| 44 |
|
| 45 |
#if defined(__GNUC__) || defined(__clang__) |
| 46 |
#define D_ATTRIBUTE_NORETURN __attribute__((noreturn)) |
| 47 |
#elif _MSC_VER |
| 48 |
#define D_ATTRIBUTE_NORETURN __declspec(noreturn) |
| 49 |
#else |
| 50 |
#define D_ATTRIBUTE_NORETURN |
| 51 |
#endif |
| 52 |
|
| 53 |
// Called after printing out fatal error messages. |
| 54 |
D_ATTRIBUTE_NORETURN void fatal(); |
| 55 |
D_ATTRIBUTE_NORETURN void halt(); |