Skip to content

Fix issues reported by dscanner #80

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

Merged
merged 5 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ install:
- export LD_LIBRARY_PATH="./linenoise-1.0:$LD_LIBRARY_PATH"

script:
- dub lint
- dub test --compiler=$DC
- dub build --compiler=$DC
- echo 10+3 | dub --compiler=$DC | grep 13
2 changes: 2 additions & 0 deletions dscanner.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[analysis.config.StaticAnalysisConfig]
undocumented_declaration_check="disabled"
2 changes: 1 addition & 1 deletion src/console.d
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import core.stdc.string : strlen;
import deimos.linenoise;
import drepl;

void main(string[] args)
void main()
{
import colorize : color, cwriteln, fg;

Expand Down
12 changes: 7 additions & 5 deletions src/drepl/engines/dmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ string mkdtemp()
}
else
{
import std.format, std.random;
import std.format : format;
import std.random: uniform;

string path;
do
{
Expand All @@ -38,7 +40,6 @@ string mkdtemp()

DMDEngine dmdEngine()
{
import core.sys.posix.unistd, std.random;
auto compiler = environment.get("DMD", "dmd");
auto tmpDir = mkdtemp();
return DMDEngine(compiler, tmpDir);
Expand Down Expand Up @@ -193,7 +194,7 @@ private:

string compileModule(string path)
{
import std.regex;
import std.regex: ctRegex, replaceAll;
auto args = [_compiler, "-I"~_tmpDir, "-of"~path~".so", "-fPIC",
"-shared", path, "-L-l:libphobos2.so"];
foreach (i; 0 .. _id)
Expand All @@ -209,7 +210,8 @@ private:

void* loadFunc(string path, string name)
{
import core.runtime, core.demangle, core.sys.posix.dlfcn;
import core.runtime: Runtime;
import core.sys.posix.dlfcn: dlerror, dlsym;

auto lib = Runtime.loadLibrary(path~".so");
if (lib is null)
Expand Down Expand Up @@ -253,7 +255,7 @@ unittest
alias ER = EngineResult;
auto dmd = dmdEngine();
assert(dmd.evalDecl("void foo(int) {}") == ER(true, "foo"));
auto er = dmd.evalStmt("foo(\"foo\");");
const auto er = dmd.evalStmt("foo(\"foo\");");
assert(!er.success);
assert(er.stdout.empty);
assert(!er.stderr.empty);
Expand Down
20 changes: 14 additions & 6 deletions src/drepl/interpreter.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import std.algorithm, std.array, std.conv, std.string, std.typecons;

struct InterpreterResult
{
enum State { success, error, incomplete };
enum State
{
success,
error,
incomplete
}

State state;
string stdout, stderr;
}
Expand Down Expand Up @@ -65,7 +71,8 @@ struct Interpreter(Engine) if (isEngine!Engine)
private:
enum Kind { Decl, Stmt, Expr, WhiteSpace, Incomplete, Error, }

import dparse.lexer, dparse.parser, dparse.rollback_allocator;
import dparse.lexer : getTokensForParser, LexerConfig, byToken, Token, StringCache, tok;
import dparse.parser : Parser;

Kind classify(in char[] input)
{
Expand Down Expand Up @@ -96,10 +103,11 @@ private:
parser.fileName = "drepl";
parser.setTokens(tokens);
parser.allocator = &allocator;
parser.messageDg = delegate(string file, size_t ln, size_t col, string msg, bool isErr) {
if (isErr)
hasErr = true;
};

void messageDg (string, size_t, size_t, string, bool isErr) {
if (isErr) hasErr = true;
}
parser.messageDg = &messageDg;
static if (kind == Kind.Decl)
{
do
Expand Down