Improve some const correctness in RGBASM

This commit is contained in:
Rangi42
2024-03-06 13:53:03 -05:00
parent 585c620945
commit 053aa80951
6 changed files with 18 additions and 13 deletions

View File

@@ -12,7 +12,7 @@ void charmap_New(char const *name, char const *baseName);
void charmap_Set(char const *name); void charmap_Set(char const *name);
void charmap_Push(); void charmap_Push();
void charmap_Pop(); void charmap_Pop();
void charmap_Add(char *mapping, uint8_t value); void charmap_Add(char const *mapping, uint8_t value);
bool charmap_HasChar(char const *input); bool charmap_HasChar(char const *input);
void charmap_Convert(char const *input, std::vector<uint8_t> &output); void charmap_Convert(char const *input, std::vector<uint8_t> &output);
size_t charmap_ConvertNext(char const *&input, std::vector<uint8_t> *output); size_t charmap_ConvertNext(char const *&input, std::vector<uint8_t> *output);

View File

@@ -10,8 +10,8 @@ void opt_G(char const chars[4]);
void opt_P(uint8_t padByte); void opt_P(uint8_t padByte);
void opt_Q(uint8_t precision); void opt_Q(uint8_t precision);
void opt_L(bool optimize); void opt_L(bool optimize);
void opt_W(char *flag); void opt_W(char const *flag);
void opt_Parse(char *option); void opt_Parse(char const *option);
void opt_Push(); void opt_Push();
void opt_Pop(); void opt_Pop();

View File

@@ -57,7 +57,7 @@ enum WarningID {
extern enum WarningState warningStates[NB_PLAIN_AND_PARAM_WARNINGS]; extern enum WarningState warningStates[NB_PLAIN_AND_PARAM_WARNINGS];
extern bool warningsAreErrors; extern bool warningsAreErrors;
void processWarningFlag(char *flag); void processWarningFlag(char const *flag);
/* /*
* Used to warn the user about problems that don't prevent the generation of * Used to warn the user about problems that don't prevent the generation of

View File

@@ -91,7 +91,7 @@ void charmap_Pop() {
charmapStack.pop(); charmapStack.pop();
} }
void charmap_Add(char *mapping, uint8_t value) { void charmap_Add(char const *mapping, uint8_t value) {
Charmap &charmap = *currentCharmap; Charmap &charmap = *currentCharmap;
size_t nodeIdx = 0; size_t nodeIdx = 0;

View File

@@ -70,11 +70,11 @@ void opt_l(bool warn) {
warnOnLdOpt = warn; warnOnLdOpt = warn;
} }
void opt_W(char *flag) { void opt_W(char const *flag) {
processWarningFlag(flag); processWarningFlag(flag);
} }
void opt_Parse(char *s) { void opt_Parse(char const *s) {
switch (s[0]) { switch (s[0]) {
case 'b': case 'b':
if (strlen(&s[1]) == 2) if (strlen(&s[1]) == 2)

View File

@@ -210,7 +210,7 @@ static uint8_t const *metaWarningCommands[NB_META_WARNINGS] = {
_weverythingCommands, _weverythingCommands,
}; };
void processWarningFlag(char *flag) { void processWarningFlag(char const *flag) {
static bool setError = false; static bool setError = false;
// First, try to match against a "meta" warning // First, try to match against a "meta" warning
@@ -235,7 +235,7 @@ void processWarningFlag(char *flag) {
// If it's not a meta warning, specially check against `-Werror` // If it's not a meta warning, specially check against `-Werror`
if (!strncmp(flag, "error", strlen("error"))) { if (!strncmp(flag, "error", strlen("error"))) {
char *errorFlag = flag + strlen("error"); char const *errorFlag = flag + strlen("error");
switch (*errorFlag) { switch (*errorFlag) {
case '\0': case '\0':
@@ -260,12 +260,12 @@ void processWarningFlag(char *flag) {
// Not an error, then check if this is a negation // Not an error, then check if this is a negation
: strncmp(flag, "no-", strlen("no-")) ? WARNING_ENABLED : strncmp(flag, "no-", strlen("no-")) ? WARNING_ENABLED
: WARNING_DISABLED; : WARNING_DISABLED;
char *rootFlag = state == WARNING_DISABLED ? flag + strlen("no-") : flag; char const *rootFlag = state == WARNING_DISABLED ? flag + strlen("no-") : flag;
// Is this a "parametric" warning? // Is this a "parametric" warning?
if (state != WARNING_DISABLED) { // The `no-` form cannot be parametrized if (state != WARNING_DISABLED) { // The `no-` form cannot be parametrized
// First, check if there is an "equals" sign followed by a decimal number // First, check if there is an "equals" sign followed by a decimal number
char *equals = strchr(rootFlag, '='); char const *equals = strchr(rootFlag, '=');
if (equals && equals[1] != '\0') { // Ignore an equal sign at the very end as well if (equals && equals[1] != '\0') { // Ignore an equal sign at the very end as well
// Is the rest of the string a decimal number? // Is the rest of the string a decimal number?
@@ -299,8 +299,13 @@ void processWarningFlag(char *flag) {
warnx("Ignoring nonsensical warning flag \"%s\"\n", flag); warnx("Ignoring nonsensical warning flag \"%s\"\n", flag);
return; return;
} }
*equals = '\0'; // Truncate the param at the '='
if (tryProcessParamWarning(rootFlag, param, param == 0 ? WARNING_DISABLED : state)) std::string truncFlag = rootFlag;
truncFlag.resize(equals - rootFlag); // Truncate the param at the '='
if (tryProcessParamWarning(
truncFlag.c_str(), param, param == 0 ? WARNING_DISABLED : state
))
return; return;
} }
} }