Skip to content

Commit baba503

Browse files
committed
dmd.error: expose ErrorSink to C++ compiler interface
1 parent 52c8c25 commit baba503

4 files changed

Lines changed: 94 additions & 20 deletions

File tree

compiler/include/dmd/errors.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,8 @@
1111
#pragma once
1212

1313
#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-
message = 3,
24-
};
14+
#include "errorsink.h"
15+
#include "globals.h"
2516

2617
#if defined(__GNUC__)
2718
#define D_ATTRIBUTE_FORMAT(m, n) __attribute__((format(printf, m, n))) __attribute__((nonnull (m)))
@@ -51,3 +42,12 @@ D_ATTRIBUTE_FORMAT(2, 3) void message(Loc loc, const char *format, ...);
5142
// Called after printing out fatal error messages.
5243
D_ATTRIBUTE_NORETURN void fatal();
5344
D_ATTRIBUTE_NORETURN void halt();
45+
46+
class ErrorSinkCompiler : public ErrorSink
47+
{
48+
public:
49+
uint32_t errorLimit;
50+
Diagnostic useWarnings;
51+
Diagnostic useDeprecated;
52+
d_bool showGaggedErrors;
53+
};

compiler/include/dmd/errorsink.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
/* Compiler implementation of the D programming language
3+
* Copyright (C) 1999-2026 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+
#include "errorsink.h"
15+
16+
struct Loc;
17+
18+
// Constants used to discriminate kinds of error messages.
19+
enum class ErrorKind
20+
{
21+
warning = 0,
22+
deprecation = 1,
23+
error = 2,
24+
message = 3,
25+
};
26+
27+
class ErrorSink
28+
{
29+
public:
30+
virtual void verror(Loc loc, const char *format, va_list ap) = 0;
31+
virtual void verrorSupplemental(Loc loc, const char *format, va_list ap) = 0;
32+
virtual void vwarning(Loc loc, const char *format, va_list ap) = 0;
33+
virtual void vwarningSupplemental(Loc loc, const char *format, va_list ap) = 0;
34+
virtual void vmessage(Loc loc, const char *format, va_list ap) = 0;
35+
virtual void vdeprecation(Loc loc, const char *format, va_list ap) = 0;
36+
virtual void vdeprecationSupplemental(Loc loc, const char *format, va_list ap) = 0;
37+
38+
virtual void error(Loc loc, const char *format, ...);
39+
virtual void errorSupplemental(Loc loc, const char *format, ...);
40+
virtual void warning(Loc loc, const char *format, ...);
41+
virtual void warningSupplemental(Loc loc, const char *format, ...);
42+
virtual void message(Loc loc, const char *format, ...);
43+
virtual void deprecation(Loc loc, const char *format, ...);
44+
virtual void deprecationSupplemental(Loc loc, const char *format, ...);
45+
virtual void plugSink();
46+
};
47+
48+
class ErrorSinkNull : public ErrorSink
49+
{
50+
public:
51+
void verror(Loc loc, const char *format, va_list ap) override;
52+
void verrorSupplemental(Loc loc, const char *format, va_list ap) override;
53+
void vwarning(Loc loc, const char *format, va_list ap) override;
54+
void vwarningSupplemental(Loc loc, const char *format, va_list ap) override;
55+
void vmessage(Loc loc, const char *format, va_list ap) override;
56+
void vdeprecation(Loc loc, const char *format, va_list ap) override;
57+
void vdeprecationSupplemental(Loc loc, const char *format, va_list ap) override;
58+
};
59+
60+
class ErrorSinkLatch : public ErrorSinkNull
61+
{
62+
public:
63+
bool sawErrors;
64+
65+
void verror(Loc loc, const char *format, va_list ap) override;
66+
};
67+
68+
class ErrorSinkStderr : public ErrorSink
69+
{
70+
public:
71+
void verror(Loc loc, const char *format, va_list ap) override;
72+
void verrorSupplemental(Loc loc, const char *format, va_list ap) override;
73+
void vwarning(Loc loc, const char *format, va_list ap) override;
74+
void vwarningSupplemental(Loc loc, const char *format, va_list ap) override;
75+
void vdeprecation(Loc loc, const char *format, va_list ap) override;
76+
void vmessage(Loc loc, const char *format, va_list ap) override;
77+
void vdeprecationSupplemental(Loc loc, const char *format, va_list ap) override;
78+
};

compiler/src/dmd/errors.d

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ nothrow:
3636
* and delegates the actual output to the virtual $(D emit) method, which
3737
* subclasses such as $(D dmd.sarif.ErrorSinkSarif) override to change format.
3838
*/
39-
class ErrorSinkCompiler : ErrorSink
39+
extern (C++) class ErrorSinkCompiler : ErrorSink
4040
{
4141
/// Maximum number of errors/deprecations to display before calling $(D fatal).
4242
/// 0 means unlimited.
@@ -59,7 +59,6 @@ class ErrorSinkCompiler : ErrorSink
5959
}
6060

6161
nothrow:
62-
extern (C++):
6362

6463
// Overrides of the abstract ErrorSink methods convert Loc to SourceLoc
6564
// and dispatch to the SourceLoc-taking overload that holds the gating body.

compiler/src/dmd/errorsink.d

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ enum ErrorKind
2727
/***************************************
2828
* Where error/warning/deprecation messages go.
2929
*/
30-
abstract class ErrorSink
30+
extern (C++) abstract class ErrorSink
3131
{
3232
nothrow:
3333
extern (C++):
@@ -177,10 +177,9 @@ else
177177
/*****************************************
178178
* Just ignores the messages.
179179
*/
180-
class ErrorSinkNull : ErrorSink
180+
extern (C++) class ErrorSinkNull : ErrorSink
181181
{
182182
nothrow:
183-
extern (C++):
184183
override:
185184

186185
void verror(Loc loc, const(char)* format, va_list ap) { }
@@ -201,10 +200,9 @@ class ErrorSinkNull : ErrorSink
201200
/*****************************************
202201
* Ignores the messages, but sets `sawErrors` for any calls to `error()`
203202
*/
204-
class ErrorSinkLatch : ErrorSinkNull
203+
extern (C++) class ErrorSinkLatch : ErrorSinkNull
205204
{
206205
nothrow:
207-
extern (C++):
208206
override:
209207

210208
bool sawErrors;
@@ -216,13 +214,12 @@ class ErrorSinkLatch : ErrorSinkNull
216214
* Simplest implementation, just sends messages to stderr.
217215
* See also: ErrorSinkCompiler.
218216
*/
219-
class ErrorSinkStderr : ErrorSink
217+
extern (C++) class ErrorSinkStderr : ErrorSink
220218
{
221219
import core.stdc.stdio;
222220
import core.stdc.stdarg;
223221

224222
nothrow:
225-
extern (C++):
226223
override:
227224

228225
void verror(Loc loc, const(char)* format, va_list ap)

0 commit comments

Comments
 (0)