From aa51fde056b2e497de10412f30483881f74019fa Mon Sep 17 00:00:00 2001 From: marcobaye Date: Mon, 22 Jun 2020 20:32:38 +0000 Subject: [PATCH] Added warning about unusual number of digits in binary literals, and a CLI switch to disable that warning. git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@257 4df02467-bbd4-4a76-a152-e7ce94205b78 --- docs/Errors.txt | 6 ++++++ docs/QuickRef.txt | 5 ++++- src/acme.c | 5 +++++ src/alu.c | 2 ++ src/global.c | 1 + src/global.h | 1 + 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/Errors.txt b/docs/Errors.txt index dc0899e..280709c 100644 --- a/docs/Errors.txt +++ b/docs/Errors.txt @@ -56,6 +56,12 @@ Hex literal without any digits. A special literal was started, but then no digits followed. Expect this to become an error in future! +Binary literal with strange number of digits. + This warning is given if the number of digits in a binary literal + is not a multiple of four. This is useful when you meant to write + %#....... but actually wrote %#........ by mistake. See? :P + You can disable this warning using the CLI switch "-Wno-bin-len". + Bug in ACME, code follows A situation has been encountered implying there is a bug in ACME. See the last section in this file. diff --git a/docs/QuickRef.txt b/docs/QuickRef.txt index d5faf06..8aef78f 100644 --- a/docs/QuickRef.txt +++ b/docs/QuickRef.txt @@ -283,6 +283,9 @@ Available options are: same time enables warnings about the _new_ "!for" syntax. Internally, this does exactly the same as what happens when the "--dialect 0.94.8" CLI switch is used... + -Wno-bin-len + Do not complain about unusual number of digits in a binary + literal. -Wtype-mismatch Enables type checking system (warns about wrong types). @@ -398,7 +401,7 @@ Examples Notes $d011 hexadecimal values are indicated by either a 0xffd2 leading "$" or a leading "0x". &1701 an octal value, indicated by "&" -%010010 binary values are indicated by either a leading "%" +%1010 binary values are indicated by either a leading "%" %....#... or a leading "0b". In binary values, you can 0b01100110 substitute the characters "0" and "1" by "." and "#" respectively. This way the values are much diff --git a/src/acme.c b/src/acme.c index 8ff98b9..aea7677 100644 --- a/src/acme.c +++ b/src/acme.c @@ -70,6 +70,7 @@ static const char arg_vicelabels[] = "VICE labels filename"; // options for "-W" #define OPTIONWNO_LABEL_INDENT "no-label-indent" #define OPTIONWNO_OLD_FOR "no-old-for" +#define OPTIONWNO_BIN_LEN "no-bin-len" #define OPTIONWTYPE_MISMATCH "type-mismatch" @@ -141,6 +142,7 @@ static void show_help_and_exit(void) // TODO: replace these: " -W" OPTIONWNO_LABEL_INDENT " suppress warnings about indented labels\n" " -W" OPTIONWNO_OLD_FOR " suppress warnings about old \"!for\" syntax\n" +" -W" OPTIONWNO_BIN_LEN " suppress warnings about lengths of binary literals\n" " -W" OPTIONWTYPE_MISMATCH " enable type checking (warn about type mismatch)\n" // with this line and add a separate function: //" -W show warning level options\n" @@ -606,6 +608,9 @@ static char short_option(const char *argument) } else if (strcmp(argument + 1, OPTIONWNO_OLD_FOR) == 0) { config.wanted_version = VER_NEWFORSYNTAX - 1; goto done; + } else if (strcmp(argument + 1, OPTIONWNO_BIN_LEN) == 0) { + config.warn_bin_mask = 0; + goto done; } else if (strcmp(argument + 1, OPTIONWTYPE_MISMATCH) == 0) { config.warn_on_type_mismatch = TRUE; goto done; diff --git a/src/alu.c b/src/alu.c index dd41966..3cd9810 100644 --- a/src/alu.c +++ b/src/alu.c @@ -491,6 +491,8 @@ static void parse_binary_literal(void) // Now GotByte = "%" or "b" } if (!digits) Throw_warning("Binary literal without any digits."); // FIXME - make into error! + if (digits & config.warn_bin_mask) + Throw_first_pass_warning("Binary literal with strange number of digits."); // set force bits if (config.honor_leading_zeroes) { if (digits > 8) { diff --git a/src/global.c b/src/global.c index adf4b7b..e678f95 100644 --- a/src/global.c +++ b/src/global.c @@ -121,6 +121,7 @@ void config_default(struct config *conf) conf->process_verbosity = 0; // level of additional output conf->warn_on_indented_labels = TRUE; // warn if indented label is encountered conf->warn_on_type_mismatch = FALSE; // use type-checking system + conf->warn_bin_mask = 3; // %11 -> warn if not divisible by four conf->max_errors = MAXERRORS; // errors before giving up conf->format_msvc = FALSE; // enabled by --msvc conf->format_color = FALSE; // enabled by --color diff --git a/src/global.h b/src/global.h index e6a14ac..b22eb2d 100644 --- a/src/global.h +++ b/src/global.h @@ -80,6 +80,7 @@ struct config { int process_verbosity; // level of additional output boolean warn_on_indented_labels; // warn if indented label is encountered boolean warn_on_type_mismatch; // use type-checking system + int warn_bin_mask; // bitmask for digit counter of binary literals signed long max_errors; // errors before giving up boolean format_msvc; // enabled by --msvc boolean format_color; // enabled by --color