diff --git a/dsymbol b/dsymbol index aa4db35b..2d599905 160000 --- a/dsymbol +++ b/dsymbol @@ -1 +1 @@ -Subproject commit aa4db35bee875a3c937cdd78b7f2e8c3a475fe79 +Subproject commit 2d599905eced19329e5147ffaaec532d28410cd5 diff --git a/src/dscanner/analysis/base.d b/src/dscanner/analysis/base.d index 0b92a5c2..d6e8b144 100644 --- a/src/dscanner/analysis/base.d +++ b/src/dscanner/analysis/base.d @@ -81,7 +81,7 @@ protected: override void visit(const T structDec) { inAggregate = true; - structDec.accept(this); + () @trusted { structDec.accept(this); } (); inAggregate = false; } } diff --git a/src/dscanner/analysis/enumarrayliteral.d b/src/dscanner/analysis/enumarrayliteral.d index c52c7261..1335a964 100644 --- a/src/dscanner/analysis/enumarrayliteral.d +++ b/src/dscanner/analysis/enumarrayliteral.d @@ -52,6 +52,6 @@ final class EnumArrayLiteralCheck : BaseAnalyzer ~ part.identifier.text ~ " = [ ...' instead."); } } - autoDec.accept(this); + () @trusted { autoDec.accept(this); } (); } } diff --git a/src/dscanner/analysis/redundant_attributes.d b/src/dscanner/analysis/redundant_attributes.d index 0b3a467f..caf04c08 100644 --- a/src/dscanner/analysis/redundant_attributes.d +++ b/src/dscanner/analysis/redundant_attributes.d @@ -277,7 +277,7 @@ unittest assertAnalyzerWarnings(q{ unittest { -@safe: + @safe void foo(); @system { diff --git a/src/dscanner/analysis/undocumented.d b/src/dscanner/analysis/undocumented.d index 46e3f76b..36551d16 100644 --- a/src/dscanner/analysis/undocumented.d +++ b/src/dscanner/analysis/undocumented.d @@ -265,7 +265,7 @@ private: { assert(isProtection(p)); } - body + do { stack[$ - 1].protection = p; } @@ -275,7 +275,7 @@ private: { assert(isProtection(p)); } - body + do { stack ~= ProtectionInfo(p, false); } @@ -349,4 +349,3 @@ unittest stderr.writeln("Unittest for UndocumentedDeclarationCheck passed."); } - diff --git a/src/dscanner/etags.d b/src/dscanner/etags.d index 0d8b2ffc..c62d3a2a 100644 --- a/src/dscanner/etags.d +++ b/src/dscanner/etags.d @@ -36,7 +36,7 @@ version = UseModuleContext; * tagAll = if set, tag private/package declaration too * fileNames = tags will be generated from these files */ -void printEtags(File output, bool tagAll, string[] fileNames) +void printEtags(File output, bool tagAll, string[] fileNames) @trusted { LexerConfig config; StringCache cache = StringCache(StringCache.defaultBucketCount); diff --git a/src/dscanner/highlighter.d b/src/dscanner/highlighter.d index 86860cd7..c64f6905 100644 --- a/src/dscanner/highlighter.d +++ b/src/dscanner/highlighter.d @@ -9,9 +9,12 @@ import std.stdio; import std.array; import dparse.lexer; +@safe: + // http://ethanschoonover.com/solarized void highlight(R)(ref R tokens, string fileName) { + () @trusted { stdout.writeln(q"[ @@ -31,6 +34,7 @@ html { background-color: #fdf6e3; color: #002b36; } .cons { color: #859900; font-weight: bold; }
]");
+    } ();
 
 	while (!tokens.empty)
 	{
@@ -57,17 +61,23 @@ html  { background-color: #fdf6e3; color: #002b36; }
 				// Stupid Windows automatically does a LF → CRLF, so
 				// CRLF → CRCRLF, which is obviously wrong.
 				// Strip out the CR characters here to avoid this.
+                            () @trusted {
 				stdout.write(t.text.replace("<", "<").replace("\r", ""));
+                            } ();
 			}
 			else
+                            () @trusted {
 				stdout.write(t.text.replace("<", "<"));
+                            } ();
 		}
 
 	}
-	stdout.writeln("
\n"); + () @trusted { + stdout.writeln("\n"); + } (); } -void writeSpan(string cssClass, string value) +void writeSpan(string cssClass, string value) @trusted { version (Windows) stdout.write(``, value.replace("&", diff --git a/src/dscanner/main.d b/src/dscanner/main.d index aa28f760..c089e1e4 100644 --- a/src/dscanner/main.d +++ b/src/dscanner/main.d @@ -37,12 +37,14 @@ import inifiled; import dsymbol.modulecache; +@safe: + version (unittest) - void main() +void main() @trusted { } else - int main(string[] args) +int main(string[] args) @trusted { bool sloc; bool highlight; @@ -74,48 +76,55 @@ else try { // dfmt off + () @trusted { getopt(args, std.getopt.config.caseSensitive, - "sloc|l", &sloc, - "highlight", &highlight, - "ctags|c", &ctags, - "help|h", &help, - "etags|e", &etags, - "etagsAll", &etagsAll, - "tokenCount|t", &tokenCount, - "syntaxCheck|s", &syntaxCheck, - "ast|xml", &ast, - "imports|i", &imports, - "recursiveImports", &recursiveImports, - "outline|o", &outline, - "tokenDump", &tokenDump, - "styleCheck|S", &styleCheck, - "defaultConfig", &defaultConfig, - "declaration|d", &symbolName, - "config", &configLocation, - "report", &report, - "reportFormat", &reportFormat, - "reportFile", &reportFile, - "I", &importPaths, - "version", &printVersion, - "muffinButton", &muffin, - "explore", &explore, - "skipTests", &skipTests, - "errorFormat|f", &errorFormat); + "sloc|l", &sloc, + "highlight", &highlight, + "ctags|c", &ctags, + "help|h", &help, + "etags|e", &etags, + "etagsAll", &etagsAll, + "tokenCount|t", &tokenCount, + "syntaxCheck|s", &syntaxCheck, + "ast|xml", &ast, + "imports|i", &imports, + "recursiveImports", &recursiveImports, + "outline|o", &outline, + "tokenDump", &tokenDump, + "styleCheck|S", &styleCheck, + "defaultConfig", &defaultConfig, + "declaration|d", &symbolName, + "config", &configLocation, + "report", &report, + "reportFormat", &reportFormat, + "reportFile", &reportFile, + "I", &importPaths, + "version", &printVersion, + "muffinButton", &muffin, + "explore", &explore, + "skipTests", &skipTests, + "errorFormat|f", &errorFormat); + } (); //dfmt on } catch (ConvException e) { - stderr.writeln(e.msg); + () @trusted { + stderr.writeln(e.msg); + } (); return 1; } catch (GetOptException e) { - stderr.writeln(e.msg); + () @trusted { + stderr.writeln(e.msg); + } (); return 1; } if (muffin) { + () @trusted { stdout.writeln(` ___________ __(#*O 0** @%*)__ _(%*o#*O%*0 #O#%##@)_ @@ -125,13 +134,16 @@ else |I|I|I|I|I|I|I|I|I|I| |I|I|I|I|I|I|I|I|I|I| |I|I|I|I|I|I|I|I|I|I|`); + } (); return 0; } if (explore) { + () @trusted { stdout.writeln("D-Scanner: Scanning..."); stderr.writeln("D-Scanner: No new astronomical objects discovered."); + } (); return 1; } @@ -153,7 +165,7 @@ else const(string[]) absImportPaths = importPaths.map!(a => a.absolutePath() .buildNormalizedPath()).array(); - auto alloc = scoped!(dsymbol.modulecache.ASTAllocator)(); + scope alloc = () @trusted { return new dsymbol.modulecache.ASTAllocator(); } (); auto moduleCache = ModuleCache(alloc); if (absImportPaths.length) @@ -328,7 +340,7 @@ else return 0; } -void printHelp(string programName) +void printHelp(string programName) @trusted { stderr.writefln(` Usage: %s diff --git a/src/dscanner/reports.d b/src/dscanner/reports.d index 3e0c9b79..8a98ebd2 100644 --- a/src/dscanner/reports.d +++ b/src/dscanner/reports.d @@ -12,6 +12,8 @@ import std.array : split, array, Appender, appender; import dscanner.analysis.base : Message, MessageSet; import dscanner.analysis.stats_collector; +@safe: + class DScannerJsonReporter { struct Issue @@ -146,7 +148,7 @@ class SonarQubeGenericIssueDataReporter { _issues ~= toIssues(messageSet); } - + void addMessage(Message message, bool isError = false) { _issues ~= toIssue(message, isError); @@ -185,7 +187,7 @@ class SonarQubeGenericIssueDataReporter } private static Issue toIssue(Message message, bool isError = false) - { + { // dfmt off Issue issue = { engineId: "dscanner", @@ -242,4 +244,4 @@ class SonarQubeGenericIssueDataReporter } } } -} \ No newline at end of file +} diff --git a/src/dscanner/stats.d b/src/dscanner/stats.d index af014f45..de75539f 100644 --- a/src/dscanner/stats.d +++ b/src/dscanner/stats.d @@ -9,6 +9,8 @@ import std.stdio; import std.algorithm; import dparse.lexer; +@safe: + pure nothrow bool isLineOfCode(IdType t) { switch (t) diff --git a/src/dscanner/symbol_finder.d b/src/dscanner/symbol_finder.d index 16e2e866..efb0b775 100644 --- a/src/dscanner/symbol_finder.d +++ b/src/dscanner/symbol_finder.d @@ -14,6 +14,8 @@ import std.stdio; import std.file : isFile; import std.functional : toDelegate; +@safe: + void findDeclarationOf(File output, string symbolName, string[] fileNames) { findDeclarationOf((string fileName, size_t line, size_t column) @@ -30,7 +32,7 @@ alias OutputHandler = void delegate(string fileName, size_t line, size_t column) /// output = Callback which gets called when a declaration is found /// symbolName = Symbol name to search for /// fileNames = An array of file names which might contain stdin to read from stdin -void findDeclarationOf(scope OutputHandler output, string symbolName, string[] fileNames) +void findDeclarationOf(scope OutputHandler output, string symbolName, string[] fileNames) @trusted { import std.array : uninitializedArray, array; import std.conv : to; @@ -136,7 +138,7 @@ class FinderVisitor : ASTVisitor { if (t.name.text == symbolName) output(fileName, t.name.line, t.name.column); - t.accept(this); + () @trusted { t.accept(this); } (); } } diff --git a/src/dscanner/utils.d b/src/dscanner/utils.d index 4c7edb7d..00f24401 100644 --- a/src/dscanner/utils.d +++ b/src/dscanner/utils.d @@ -7,6 +7,8 @@ import std.encoding : BOM, BOMSeq, EncodingException, getBOM; import std.format : format; import std.file : exists, read; +@safe: + private void processBOM(ref ubyte[] sourceCode, string fname) { enum spec = "D-Scanner does not support %s-encoded files (%s)"; @@ -54,7 +56,7 @@ ubyte[] readStdin() ubyte[4096] buf; while (true) { - auto b = stdin.rawRead(buf); + auto b = () @trusted { return stdin.rawRead(buf); } (); if (b.length == 0) break; sourceCode.put(b); @@ -70,12 +72,12 @@ ubyte[] readFile(string fileName) return readStdin(); if (!exists(fileName)) { - stderr.writefln("%s does not exist", fileName); + () @trusted { stderr.writefln("%s does not exist", fileName); } (); return []; } File f = File(fileName); ubyte[] sourceCode; - sourceCode = cast(ubyte[]) fileName.read(); + () @trusted { sourceCode = cast(ubyte[]) fileName.read(); } (); sourceCode.processBOM(fileName); return sourceCode; } @@ -104,13 +106,15 @@ string[] expandArgs(string[] args) if (arg == "stdin" || isFileSafe(arg)) rVal ~= arg; else + () @trusted { foreach (item; dirEntries(arg, SpanMode.breadth).map!(a => a.name)) - { + { if (isFileSafe(item) && (item.endsWith(`.d`) || item.endsWith(`.di`)) && !item.canFind(dirSeparator ~ '.')) - rVal ~= item; + rVal ~= item; else - continue; - } + continue; + } + } (); } return rVal; }