Skip to content

Commit

Permalink
Merge pull request #1726 from joakim-brannstrom/mutate-fix-analyze-depth
Browse files Browse the repository at this point in the history
mutate: allow analysis of more complex code
  • Loading branch information
joakim-brannstrom-work1 authored Jan 29, 2024
2 parents bb1b348 + d05df75 commit c553342
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions libs/libclang_ast/source/libclang_ast/ast/base_visitor.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ abstract class Visitor {
void decr() scope {
}

// called on each node to check if it should be visited
bool precondition() scope {
return true;
}

void visit(scope const TranslationUnit) {
}

Expand Down
6 changes: 6 additions & 0 deletions libs/libclang_ast/source/libclang_ast/ast/tree.d
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ struct ClangAST(VisitorT) {
void accept(VisitorT)(scope const Cursor cursor, scope VisitorT visitor) @safe {
import clang.Visitor : Visitor;

if (!visitor.precondition)
return;

visitor.incr();
scope (exit)
visitor.decr();
Expand Down Expand Up @@ -90,6 +93,9 @@ void dispatch(VisitorT)(scope const Cursor cursor, scope VisitorT visitor) @trus
import libclang_ast.ast.nodes;
import std.conv : to;

if (!visitor.precondition)
return;

static if (__traits(hasMember, VisitorT, "ignoreCursors")) {
const h = cursor.toHash;
if (h in visitor.ignoreCursors) {
Expand Down
2 changes: 2 additions & 0 deletions news.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ void fn(int x) {
compilation errors. All known problems have been fixed which should speedup
mutation testing alot.
* Update jquery to v3.7.1 to fix three potential security vulnerabilities.
* Allow analysis of more complext code by not discarding the whole AST because
some AST branches have a "too high" depth.
# v5.0 Limestone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ final class BaseVisitor : ExtendedVisitor {
return false;
}

override bool precondition() scope @safe {
// to avoid infinite recursion, which may occur in e.g. postgresql, block
// segfault on 300
return indent < 150;
}

override void incr() scope @safe {
++indent;
lastDecr.clear;
Expand Down Expand Up @@ -1107,12 +1113,6 @@ final class BaseVisitor : ExtendedVisitor {

override void visit(scope const IfStmt v) @trusted {
mixin(mixinNodeLog!());
// to avoid infinite recursion, which may occur in e.g. postgresql, block
// segfault on 300
if (indent > 100) {
throw new Exception("max analyze depth reached (100)");
}

auto n = ast.get.make!(analyze.BranchBundle);
if (isConstExpr(v))
n.schemaBlacklist = true;
Expand Down

0 comments on commit c553342

Please sign in to comment.