Skip to content

Commit cf85146

Browse files
authored
Refactoring and enhancements to RGBASM warnings (#1526)
* Allow a `no-` prefix to negate "meta" warnings (`-Wno-all`, `-Wno-extra`, `-Wno-everything`) * Allow `-Wno-error=...` to override `-Werror` (including for "meta" warnings)
1 parent a9e49a0 commit cf85146

File tree

5 files changed

+238
-293
lines changed

5 files changed

+238
-293
lines changed

include/asm/warning.hpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
extern unsigned int nbErrors, maxErrors;
77

8-
enum WarningState { WARNING_DEFAULT, WARNING_DISABLED, WARNING_ENABLED, WARNING_ERROR };
9-
108
enum WarningID {
119
WARNING_ASSERT, // Assertions
1210
WARNING_BACKWARDS_FOR, // `for` loop with backwards range
@@ -26,10 +24,9 @@ enum WarningID {
2624

2725
NB_PLAIN_WARNINGS,
2826

29-
// Warnings past this point are "parametric" warnings, only mapping to a single flag
30-
#define PARAM_WARNINGS_START NB_PLAIN_WARNINGS
27+
// Warnings past this point are "parametric" warnings, only mapping to a single flag
3128
// Treating string as number may lose some bits
32-
WARNING_NUMERIC_STRING_1 = PARAM_WARNINGS_START,
29+
WARNING_NUMERIC_STRING_1 = NB_PLAIN_WARNINGS,
3330
WARNING_NUMERIC_STRING_2,
3431
// Purging an exported symbol or label
3532
WARNING_PURGE_1,
@@ -41,20 +38,24 @@ enum WarningID {
4138
WARNING_UNMAPPED_CHAR_1,
4239
WARNING_UNMAPPED_CHAR_2,
4340

44-
NB_PLAIN_AND_PARAM_WARNINGS,
45-
#define NB_PARAM_WARNINGS (NB_PLAIN_AND_PARAM_WARNINGS - PARAM_WARNINGS_START)
41+
NB_WARNINGS,
42+
};
4643

47-
// Warnings past this point are "meta" warnings
48-
#define META_WARNINGS_START NB_PLAIN_AND_PARAM_WARNINGS
49-
WARNING_ALL = META_WARNINGS_START,
50-
WARNING_EXTRA,
51-
WARNING_EVERYTHING,
44+
enum WarningAbled { WARNING_DEFAULT, WARNING_ENABLED, WARNING_DISABLED };
5245

53-
NB_WARNINGS,
54-
#define NB_META_WARNINGS (NB_WARNINGS - META_WARNINGS_START)
46+
struct WarningState {
47+
WarningAbled state;
48+
WarningAbled error;
49+
50+
void update(WarningState other);
51+
};
52+
53+
struct Diagnostics {
54+
WarningState flagStates[NB_WARNINGS];
55+
WarningState metaStates[NB_WARNINGS];
5556
};
5657

57-
extern WarningState warningStates[NB_PLAIN_AND_PARAM_WARNINGS];
58+
extern Diagnostics warningStates;
5859
extern bool warningsAreErrors;
5960

6061
void processWarningFlag(char const *flag);

man/rgbasm.1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,19 @@ The following options alter the way warnings are processed.
212212
.Bl -tag -width Ds
213213
.It Fl Werror
214214
Make all warnings into errors.
215+
This can be negated as
216+
.Fl Wno-error
217+
to prevent turning all warnings into errors.
215218
.It Fl Werror=
216-
Make the specified warning into an error.
219+
Make the specified warning or meta warning into an error.
217220
A warning's name is appended
218221
.Pq example: Fl Werror=obsolete ,
219222
and this warning is implicitly enabled and turned into an error.
220-
This is an error if used with a meta warning, such as
221-
.Fl Werror=all .
223+
This can be negated as
224+
.Fl Wno-error=
225+
to prevent turning a specified warning into an error, even if
226+
.Fl Werror
227+
is in effect.
222228
.El
223229
.Pp
224230
The following warnings are
@@ -240,6 +246,10 @@ Note that each of these flag also has a negation (for example,
240246
.Fl Wcharmap-redef
241247
enables the warning that
242248
.Fl Wno-charmap-redef
249+
disables; and
250+
.Fl Wall
251+
enables every warning that
252+
.Fl Wno-all
243253
disables).
244254
Only the non-default flag is listed here.
245255
Ignoring the

src/asm/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ int main(int argc, char *argv[]) {
293293
break;
294294

295295
case 'W':
296-
processWarningFlag(musl_optarg);
296+
opt_W(musl_optarg);
297297
break;
298298

299299
case 'w':

src/asm/opt.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@
1313
#include "asm/section.hpp"
1414
#include "asm/warning.hpp"
1515

16-
static constexpr size_t numWarningStates = sizeof(warningStates);
17-
1816
struct OptStackEntry {
1917
char binary[2];
2018
char gbgfx[4];
2119
uint8_t fixPrecision;
2220
uint8_t fillByte;
2321
bool warningsAreErrors;
2422
size_t maxRecursionDepth;
25-
WarningState warningStates[numWarningStates];
23+
Diagnostics warningStates;
2624
};
2725

2826
static std::stack<OptStackEntry> stack;
@@ -160,7 +158,7 @@ void opt_Push() {
160158

161159
// Both of these pulled from warning.hpp
162160
entry.warningsAreErrors = warningsAreErrors;
163-
memcpy(entry.warningStates, warningStates, numWarningStates);
161+
entry.warningStates = warningStates;
164162

165163
entry.maxRecursionDepth = maxRecursionDepth; // Pulled from fstack.h
166164

@@ -184,5 +182,5 @@ void opt_Pop() {
184182

185183
// opt_W does not apply a whole warning state; it processes one flag string
186184
warningsAreErrors = entry.warningsAreErrors;
187-
memcpy(warningStates, entry.warningStates, numWarningStates);
185+
warningStates = entry.warningStates;
188186
}

0 commit comments

Comments
 (0)