Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Don't use cast with C++ linkage
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugen Wissner authored and Eugen Wissner committed Apr 6, 2022
1 parent af95b3e commit 5a1352c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion make.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def clean
build argument
when 'run'
build 'debug'
system 'build/cogito', 'tools/sample.d'
system 'build/cogito', '--format', 'verbose', 'tools/sample.d'
when 'test'
build 'unittest'
system 'build/test', '-s'
Expand Down
9 changes: 6 additions & 3 deletions src/cogito/visitor.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module cogito.visitor;

import core.stdc.string;
import dmd.ast_node;
import dmd.astcodegen;
import dmd.parsetimevisitor;
Expand Down Expand Up @@ -495,10 +496,10 @@ extern(C++) final class CognitiveVisitor : SemanticTimeTransitiveVisitor
}
foreach (elseDeclaration; *declaration)
{
auto elseIf = cast(AST.StaticIfDeclaration) elseDeclaration;
if (elseIf !is null)
if (strcmp(elseDeclaration.kind, "static if") == 0)
{
if (elseIf.decl)
auto elseIf = cast(AST.StaticIfDeclaration) elseDeclaration;
if (elseIf.decl !is null)
{
increase;

Expand All @@ -513,6 +514,8 @@ extern(C++) final class CognitiveVisitor : SemanticTimeTransitiveVisitor
}
else
{
increase;

++this.depth;
elseDeclaration.accept(this);
--this.depth;
Expand Down
4 changes: 3 additions & 1 deletion tests/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cogito.tests.expressions;
import cogito.tests.functions;
import cogito.tests.meta;
import cogito.tests.statements;
import cogito.tests.visitor;

int main(string[] args)
{
Expand All @@ -13,6 +14,7 @@ int main(string[] args)
cogito.tests.expressions,
cogito.tests.functions,
cogito.tests.meta,
cogito.tests.statements
cogito.tests.statements,
cogito.tests.visitor
)(args);
}
4 changes: 2 additions & 2 deletions tests/cogito/functions.d
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ interface C
}
});

assert(meter.tryMatch!((Source source) => source.inner[].front.name.toString) == "C");
assert(meter.tryMatch!((Source source) => source.inner[].front.name) == "C");
}

@("Union")
Expand All @@ -95,7 +95,7 @@ union U
}
});

assert(meter.tryMatch!((Source source) => source.inner[].front.name.toString) == "U");
assert(meter.tryMatch!((Source source) => source.inner[].front.name) == "U");
}

@("Constructor")
Expand Down
22 changes: 22 additions & 0 deletions tests/cogito/visitor.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module cogito.tests.visitor;

import cogito;
import std.sumtype;

unittest
{
auto meter = runOnCode(q{
struct S
{
static if (true)
{
}
else
{
ubyte[T.sizeof] data;
}
}
});

assert(meter.tryMatch!((Source source) => source.score) == 2);
}

0 comments on commit 5a1352c

Please sign in to comment.