Skip to content

Commit

Permalink
Fix implicit conversion of dynamic array to bool
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-tan committed Apr 8, 2015
1 parent 4a7f98d commit f628b56
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.
22 changes: 11 additions & 11 deletions DustMite/dustmite.d
Expand Up @@ -177,7 +177,7 @@ EOS");
return showHelp ? 0 : 64; // EX_USAGE
}

enforce(!(stripComments && coverageDir), "Sorry, --strip-comments is not compatible with --coverage");
enforce(!(stripComments && coverageDir.length), "Sorry, --strip-comments is not compatible with --coverage");

dir = args[1];
if (isDirSeparator(dir[$-1]))
Expand Down Expand Up @@ -216,7 +216,7 @@ EOS");

applyNoRemoveMagic();
applyNoRemoveRegex(noRemoveStr, reduceOnly);
if (coverageDir)
if (coverageDir.length)
loadCoverage(coverageDir);
if (!obfuscate && !noOptimize)
optimize(root);
Expand Down Expand Up @@ -662,10 +662,10 @@ void dump(Entity root, ref Reduction reduction, void delegate(string) handleFile
dumpEntity(c);
}
else
if (e.head || e.tail)
if (e.head.length || e.tail.length)
{
assert(e.children.length==0);
if (e.head)
if (e.head.length)
{
if (e.head == reduction.from)
handleText(reduction.to);
Expand Down Expand Up @@ -1030,7 +1030,7 @@ bool test(Reduction reduction)
{
tests++;

if (globalCache)
if (globalCache.length)
{
if (!exists(globalCache)) mkdirRecurse(globalCache);
string cacheBase = absolutePath(buildPath(globalCache, formatHash(digest))) ~ "-";
Expand Down Expand Up @@ -1312,20 +1312,20 @@ void dumpSet(string fn)
"[",
e.noRemove ? "!" : "",
" ",
e.isFile ? e.filename ? printableFN(e.filename) ~ " " : null : e.head ? printable(e.head) ~ " " : null,
e.tail ? printable(e.tail) ~ " " : null,
e.comment ? "/* " ~ e.comment ~ " */ " : null,
e.isFile ? e.filename.length ? printableFN(e.filename) ~ " " : null : e.head.length ? printable(e.head) ~ " " : null,
e.tail.length ? printable(e.tail) ~ " " : null,
e.comment.length ? "/* " ~ e.comment ~ " */ " : null,
"]"
);
}
else
{
f.writeln("[", e.noRemove ? "!" : "", e.comment ? " // " ~ e.comment : null);
f.writeln("[", e.noRemove ? "!" : "", e.comment.length ? " // " ~ e.comment : null);
if (e.isFile) f.writeln(prefix, " ", printableFN(e.filename));
if (e.head) f.writeln(prefix, " ", printable(e.head));
if (e.head.length) f.writeln(prefix, " ", printable(e.head));
foreach (c; e.children)
print(c, depth+1);
if (e.tail) f.writeln(prefix, " ", printable(e.tail));
if (e.tail.length) f.writeln(prefix, " ", printable(e.tail));
f.write(prefix, "]");
}
if (e.id in dependents || trace)
Expand Down
30 changes: 15 additions & 15 deletions DustMite/splitter.d
Expand Up @@ -440,7 +440,7 @@ struct DSplitter
advance();
break;
case 'r':
if (consume(`r"`))
if (consume(`r"`).length)
{
result = Token.other;
while (advance() != '"')
Expand All @@ -465,7 +465,7 @@ struct DSplitter
if (consume('*'))
{
result = Token.comment;
while (!consume("*/"))
while (!consume("*/").length)
advance();
}
else
Expand All @@ -475,10 +475,10 @@ struct DSplitter
int commentLevel = 1;
while (commentLevel)
{
if (consume("/+"))
if (consume("/+").length)
commentLevel++;
else
if (consume("+/"))
if (consume("+/").length)
commentLevel--;
else
advance();
Expand All @@ -488,11 +488,11 @@ struct DSplitter
goto default;
break;
case '@':
if (consume("disable")
|| consume("property")
|| consume("safe")
|| consume("trusted")
|| consume("system")
if (consume("disable").length
|| consume("property").length
|| consume("safe").length
|| consume("trusted").length
|| consume("system").length
)
return Token.other;
goto default;
Expand All @@ -514,7 +514,7 @@ struct DSplitter
foreach (Token t; Token.init..Token.max)
{
auto text = tokenText[t];
if (!text)
if (!text.length)
continue;
if (!s[i..$].startsWith(text))
continue;
Expand All @@ -528,7 +528,7 @@ struct DSplitter
if (bestLength)
{
auto consumed = consume(tokenText[best]);
assert(consumed);
assert(consumed.length);
return best;
}

Expand Down Expand Up @@ -703,7 +703,7 @@ struct DSplitter
reset(code);
auto entity = new Entity;
parseScope(entity, Token.none);
assert(!entity.head && !entity.tail);
assert(!entity.head.length && !entity.tail.length);
postProcess(entity.children);
return [entity];
}
Expand All @@ -724,7 +724,7 @@ struct DSplitter
{
if (!result.length)
result ~= new Entity();
if (!result[$-1].tail)
if (!result[$-1].tail.length)
result[$-1].tail = span;
else
{
Expand Down Expand Up @@ -793,7 +793,7 @@ struct DSplitter

size_t[] points;
foreach_reverse (i, e; entities[0..$-1])
if (getSeparatorType(e.token) == SeparatorType.binary && e.children)
if (getSeparatorType(e.token) == SeparatorType.binary && e.children.length)
points ~= i;

if (points.length)
Expand All @@ -814,7 +814,7 @@ struct DSplitter
static void postProcessDependencyBlock(ref Entity[] entities)
{
foreach (i, e; entities)
if (i && !e.token && e.children.length && getSeparatorType(e.children[0].token) == SeparatorType.binary && !e.children[0].children)
if (i && !e.token && e.children.length && getSeparatorType(e.children[0].token) == SeparatorType.binary && !e.children[0].children.length)
e.children[0].dependencies ~= entities[i-1];
}

Expand Down
4 changes: 2 additions & 2 deletions catdoc.d
Expand Up @@ -25,7 +25,7 @@ Usage:

string ofile;
getopt(args, "o", &ofile);
if (!ofile)
if (!ofile.length)
{
writeln("catdoc: set output file with -o=filename");
return 1;
Expand Down Expand Up @@ -53,7 +53,7 @@ Usage:
if (i + 8 < input.length && std.string.icmp(input[i + 1 .. i + 8], "Macros:") == 0)
{
comment ~= input[4 .. i + 1];
if (!macros)
if (!macros.length)
macros = "Macros:\n";
macros ~= input[i + 8 .. $];
goto L1;
Expand Down
24 changes: 12 additions & 12 deletions rdmd.d
Expand Up @@ -76,7 +76,7 @@ int main(string[] args)
else if (value[0] == 'd')
{
// -odmydir passed
if (!exe) // Don't let -od override -of
if (!exe.length) // Don't let -od override -of
{
// add a trailing dir separator to clarify it's a dir
exe = value[1 .. $];
Expand Down Expand Up @@ -148,7 +148,7 @@ int main(string[] args)
* To see the full discussion please refer to:
* https://github.com/D-Programming-Language/tools/pull/122
*/
if ((makeDepend || makeDepFile) && (!exe || exe.endsWith(dirSeparator)))
if ((makeDepend || makeDepFile.length) && (!exe.length || exe.endsWith(dirSeparator)))
{
stderr.write(helpString);
stderr.writeln();
Expand All @@ -164,8 +164,8 @@ int main(string[] args)
string root;
string[] programArgs;
// Just evaluate this program!
enforce(!(loop && eval), "Cannot mix --eval and --loop.");
if (loop)
enforce(!(loop.length && eval.length), "Cannot mix --eval and --loop.");
if (loop.length)
{
enforce(programPos == args.length, "Cannot have both --loop and a " ~
"program file ('" ~ args[programPos] ~ "').");
Expand All @@ -174,7 +174,7 @@ int main(string[] args)
~ std.string.join(loop, "\n")
~ ";\n} }");
}
else if (eval)
else if (eval.length)
{
enforce(programPos == args.length, "Cannot have both --eval and a " ~
"program file ('" ~ args[programPos] ~ "').");
Expand Down Expand Up @@ -203,10 +203,10 @@ int main(string[] args)
string outExt = lib ? libExt : binExt;

// --build-only implies the user would like a binary in the program's directory
if (buildOnly && !exe)
if (buildOnly && !exe.length)
exe = exeDirname ~ dirSeparator;

if (exe && exe.endsWith(dirSeparator))
if (exe.length && exe.endsWith(dirSeparator))
{
// user specified a directory, complete it to a file
exe = buildPath(exe, exeBasename) ~ outExt;
Expand Down Expand Up @@ -263,7 +263,7 @@ int main(string[] args)
*/
string buildWitness;
SysTime lastBuildTime = SysTime.min;
if (exe)
if (exe.length)
{
// user-specified exe name
buildWitness = buildPath(workDir, ".built");
Expand Down Expand Up @@ -395,7 +395,7 @@ private @property string myOwnTmpDir()
private string getWorkPath(in string root, in string[] compilerFlags)
{
static string workPath;
if (workPath)
if (workPath.length)
return workPath;

enum string[] irrelevantSwitches = [
Expand Down Expand Up @@ -547,7 +547,7 @@ private int run(string[] args, string output = null, bool replace = false)
yap(replace ? "exec " : "spawn ", args.text);
if (dryRun) return 0;

if (replace && !output)
if (replace && !output.length)
{
version (Windows)
{ /* Windows doesn't have exec, fall back to spawnProcess+wait */ }
Expand All @@ -560,7 +560,7 @@ private int run(string[] args, string output = null, bool replace = false)
}

File outputFile;
if (output)
if (output.length)
outputFile = File(output, "wb");
else
outputFile = stdout;
Expand Down Expand Up @@ -657,7 +657,7 @@ private string[string] getDependencies(string rootModule, string workDir,
case "library":
immutable libName = captures[2].strip();
immutable libPath = findLib(libName);
if (libPath)
if (libPath.length)
{
yap("library ", libName, " ", libPath);
result[libPath] = null;
Expand Down

0 comments on commit f628b56

Please sign in to comment.