Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring and enhancements to RGBASM warnings #1526

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions include/asm/warning.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

extern unsigned int nbErrors, maxErrors;

enum WarningState { WARNING_DEFAULT, WARNING_DISABLED, WARNING_ENABLED, WARNING_ERROR };

enum WarningID {
WARNING_ASSERT, // Assertions
WARNING_BACKWARDS_FOR, // `for` loop with backwards range
Expand All @@ -26,10 +24,9 @@ enum WarningID {

NB_PLAIN_WARNINGS,

// Warnings past this point are "parametric" warnings, only mapping to a single flag
#define PARAM_WARNINGS_START NB_PLAIN_WARNINGS
// Warnings past this point are "parametric" warnings, only mapping to a single flag
// Treating string as number may lose some bits
WARNING_NUMERIC_STRING_1 = PARAM_WARNINGS_START,
WARNING_NUMERIC_STRING_1 = NB_PLAIN_WARNINGS,
WARNING_NUMERIC_STRING_2,
// Purging an exported symbol or label
WARNING_PURGE_1,
Expand All @@ -41,20 +38,24 @@ enum WarningID {
WARNING_UNMAPPED_CHAR_1,
WARNING_UNMAPPED_CHAR_2,

NB_PLAIN_AND_PARAM_WARNINGS,
#define NB_PARAM_WARNINGS (NB_PLAIN_AND_PARAM_WARNINGS - PARAM_WARNINGS_START)
NB_WARNINGS,
};

// Warnings past this point are "meta" warnings
#define META_WARNINGS_START NB_PLAIN_AND_PARAM_WARNINGS
WARNING_ALL = META_WARNINGS_START,
WARNING_EXTRA,
WARNING_EVERYTHING,
enum WarningAbled { WARNING_DEFAULT, WARNING_ENABLED, WARNING_DISABLED };

NB_WARNINGS,
#define NB_META_WARNINGS (NB_WARNINGS - META_WARNINGS_START)
struct WarningState {
WarningAbled state;
WarningAbled error;

void update(WarningState other);
};

struct Diagnostics {
WarningState flagStates[NB_WARNINGS];
WarningState metaStates[NB_WARNINGS];
};

extern WarningState warningStates[NB_PLAIN_AND_PARAM_WARNINGS];
extern Diagnostics warningStates;
extern bool warningsAreErrors;

void processWarningFlag(char const *flag);
Expand Down
16 changes: 13 additions & 3 deletions man/rgbasm.1
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,19 @@ The following options alter the way warnings are processed.
.Bl -tag -width Ds
.It Fl Werror
Make all warnings into errors.
This can be negated as
.Fl Wno-error
to prevent turning all warnings into errors.
.It Fl Werror=
Make the specified warning into an error.
Make the specified warning or meta warning into an error.
A warning's name is appended
.Pq example: Fl Werror=obsolete ,
and this warning is implicitly enabled and turned into an error.
This is an error if used with a meta warning, such as
.Fl Werror=all .
This can be negated as
.Fl Wno-error=
to prevent turning a specified warning into an error, even if
.Fl Werror
is in effect.
.El
.Pp
The following warnings are
Expand All @@ -240,6 +246,10 @@ Note that each of these flag also has a negation (for example,
.Fl Wcharmap-redef
enables the warning that
.Fl Wno-charmap-redef
disables; and
.Fl Wall
enables every warning that
.Fl Wno-all
disables).
Only the non-default flag is listed here.
Ignoring the
Expand Down
2 changes: 1 addition & 1 deletion src/asm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ int main(int argc, char *argv[]) {
break;

case 'W':
processWarningFlag(musl_optarg);
opt_W(musl_optarg);
break;

case 'w':
Expand Down
8 changes: 3 additions & 5 deletions src/asm/opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
#include "asm/section.hpp"
#include "asm/warning.hpp"

static constexpr size_t numWarningStates = sizeof(warningStates);

struct OptStackEntry {
char binary[2];
char gbgfx[4];
uint8_t fixPrecision;
uint8_t fillByte;
bool warningsAreErrors;
size_t maxRecursionDepth;
WarningState warningStates[numWarningStates];
Diagnostics warningStates;
};

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

// Both of these pulled from warning.hpp
entry.warningsAreErrors = warningsAreErrors;
memcpy(entry.warningStates, warningStates, numWarningStates);
entry.warningStates = warningStates;

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

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

// opt_W does not apply a whole warning state; it processes one flag string
warningsAreErrors = entry.warningsAreErrors;
memcpy(warningStates, entry.warningStates, numWarningStates);
warningStates = entry.warningStates;
}
Loading