-
-
Notifications
You must be signed in to change notification settings - Fork 668
add -check command line switch #8972
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| Added -check switch to turn on and off each category of runtime checks. | ||
|
|
||
| Option("check=[assert|bounds|in|invariant|out|switch][=[on|off]]", | ||
| `Overrides default, -boundscheck, -release and -unittest options to enable or disable specific checks. | ||
| $(UL | ||
| $(LI $(B assert): assertion checking) | ||
| $(LI $(B bounds): array bounds) | ||
| $(LI $(B in): in contracts) | ||
| $(LI $(B invariant): class/struct invariants) | ||
| $(LI $(B out): out contracts) | ||
| $(LI $(B switch): switch default) | ||
| ) | ||
| $(UL | ||
| $(LI $(B on) or not specified: specified check is enabled.) | ||
| $(LI $(B off): specified check is disabled.) | ||
| )` | ||
| ) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,6 +175,7 @@ struct Param | |
| CHECKENABLE useArrayBounds = CHECKENABLE._default; // when to generate code for array bounds checks | ||
| CHECKENABLE useAssert = CHECKENABLE._default; // when to generate code for assert()'s | ||
| CHECKENABLE useSwitchError = CHECKENABLE._default; // check for switches without a default | ||
| CHECKENABLE boundscheck = CHECKENABLE._default; // state of -boundscheck switch | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this now works as documented, I think it's a bit confusing to have both |
||
|
|
||
| CHECKACTION checkAction = CHECKACTION.D; // action to take when bounds, asserts or switch defaults are violated | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -335,6 +335,19 @@ private int tryMain(size_t argc, const(char)** argv) | |
| global.params.mscrtlib = vsopt.defaultRuntimeLibrary(global.params.is64bit); | ||
| } | ||
| } | ||
|
|
||
| if (global.params.boundscheck != CHECKENABLE._default) | ||
| { | ||
| if (global.params.useArrayBounds == CHECKENABLE._default) | ||
| global.params.useArrayBounds = global.params.boundscheck; | ||
| } | ||
|
|
||
| if (global.params.useUnitTests) | ||
| { | ||
| if (global.params.useAssert == CHECKENABLE._default) | ||
| global.params.useAssert = CHECKENABLE.on; | ||
| } | ||
|
|
||
| if (global.params.release) | ||
| { | ||
| if (global.params.useInvariants == CHECKENABLE._default) | ||
|
|
@@ -376,9 +389,6 @@ private int tryMain(size_t argc, const(char)** argv) | |
| global.params.useSwitchError = CHECKENABLE.on; | ||
| } | ||
|
|
||
| if (global.params.useUnitTests) | ||
| global.params.useAssert = CHECKENABLE.on; | ||
|
|
||
| if (global.params.betterC) | ||
| { | ||
| global.params.checkAction = CHECKACTION.C; | ||
|
|
@@ -1499,6 +1509,42 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param | |
| params.useDeprecated = Diagnostic.inform; | ||
| else if (arg == "-c") // https://dlang.org/dmd.html#switch-c | ||
| params.link = false; | ||
| else if (startsWith(p + 1, "check=")) // https://dlang.org/dmd.html#switch-check | ||
| { | ||
| /* Parse: | ||
| * -check=[assert|bounds|in|invariant|out|switch][=[on|off]] | ||
| */ | ||
|
|
||
| // Check for legal option string; return true if so | ||
| static bool check(const(char)* p, string name, ref CHECKENABLE ce) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems awfully rigid, re checking for exactly |
||
| { | ||
| p += "-check=".length; | ||
| if (startsWith(p, name)) | ||
| { | ||
| p += name.length; | ||
| if (*p == 0 || | ||
| strcmp(p, "=on") == 0) | ||
| { | ||
| ce = CHECKENABLE.on; | ||
| return true; | ||
| } | ||
| else if (strcmp(p, "=off") == 0) | ||
| { | ||
| ce = CHECKENABLE.off; | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| if (!(check(p, "assert", params.useAssert ) || | ||
| check(p, "bounds", params.useArrayBounds) || | ||
| check(p, "in", params.useIn ) || | ||
| check(p, "invariant", params.useInvariants ) || | ||
| check(p, "out", params.useOut ) || | ||
| check(p, "switch", params.useSwitchError))) | ||
| goto Lerror; | ||
| } | ||
| else if (startsWith(p + 1, "checkaction=")) // https://dlang.org/dmd.html#switch-checkaction | ||
| { | ||
| /* Parse: | ||
|
|
@@ -1956,7 +2002,7 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param | |
| params.betterC = true; | ||
| else if (arg == "-noboundscheck") // https://dlang.org/dmd.html#switch-noboundscheck | ||
| { | ||
| params.useArrayBounds = CHECKENABLE.off; | ||
| params.boundscheck = CHECKENABLE.off; | ||
| } | ||
| else if (startsWith(p + 1, "boundscheck")) // https://dlang.org/dmd.html#switch-boundscheck | ||
| { | ||
|
|
@@ -1966,15 +2012,15 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param | |
| { | ||
| if (strcmp(p + 13, "on") == 0) | ||
| { | ||
| params.useArrayBounds = CHECKENABLE.on; | ||
| params.boundscheck = CHECKENABLE.on; | ||
| } | ||
| else if (strcmp(p + 13, "safeonly") == 0) | ||
| { | ||
| params.useArrayBounds = CHECKENABLE.safeonly; | ||
| params.boundscheck = CHECKENABLE.safeonly; | ||
| } | ||
| else if (strcmp(p + 13, "off") == 0) | ||
| { | ||
| params.useArrayBounds = CHECKENABLE.off; | ||
| params.boundscheck = CHECKENABLE.off; | ||
| } | ||
| else | ||
| goto Lerror; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't want to start bikeshedding, but the duplicate
=looks strange. Why not usecheck-[assert|...]?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because 1) we use
on|offelsewhere, not+|-2) I want to add asafeoption as well 3) other options may become useful than juston|off|safeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't mean to remove the on/off, but to replace the first
=with-, e.g.-check-assert=oninstead of-check=assert=on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already use
=for themvswitch.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another syntax question: is it assumed that the user will write separate
-check=assert -check=in -check=out -check=boundscalls, or do we want to support a syntax like-check=assert,bounds,in,outthat allows all the options to be specified in a single flag?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps in the future. For right now, I want to maximize simplicity.